QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298231#5062. SquareHJRWA 7ms13896kbC++231.7kb2024-01-05 20:54:342024-01-05 20:54:34

Judging History

你现在查看的是最新测评结果

  • [2024-01-05 20:54:34]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:13896kb
  • [2024-01-05 20:54:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cout<<#x<<": "<<x<<endl
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll=long long;
using ull=unsigned long long;
#define int long long
const int mo=1000000007;
vector<int> minp, primes;
 
void sieve(int n) {
    minp.assign(n + 1, 0);
    primes.clear();
    
    for (int i = 2; i <= n; i++) {
        if (minp[i] == 0) {
            minp[i] = i;
            primes.push_back(i);
        }
        
        for (auto p : primes) {
            if (i * p > n) {
                break;
            }
            minp[i * p] = p;
            if (p == minp[i]) {
                break;
            }
        }
    }
}
 
constexpr int V = 1E6;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    vector<int> res;
    for(int i=0;i<n-1;i++){
        map<int,int> mp;
        int x=a[i],y=a[i+1];
        for(auto it:primes){
            if(x==1&&y==1)
                break;
            while(x%it==0){
                x/=it;
                mp[it]++;
            }
            while(y%it==0){
                y/=it;
                mp[it]++;
            }
        }
        int cur=1;
        for(auto [a1,a2]:mp){
            if(a2%2)
                cur*=a1;
        }
        res.push_back(cur);
    }
    for(int i=1;i<res.size();i++){
        res[i]/=__gcd(res[i-1],res[i]);
    }
    ll ans=1;
    for(auto x:res){
        ans*=x;
        ans%=mo;
    }
    cout<<ans;
}
signed main(){
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    sieve(V);
    int t=1;
    while(t--){
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 12124kb

input:

3
2 3 6

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 7ms
memory: 11844kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 7ms
memory: 13896kb

input:

100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 6ms
memory: 11984kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 6ms
memory: 12004kb

input:

1
130321

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 6ms
memory: 12048kb

input:

1
85849

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: -100
Wrong Answer
time: 6ms
memory: 12020kb

input:

10
1 37249 1 193 1 193 193 193 1 37249

output:

7189057

result:

wrong answer 1st numbers differ - expected: '387487994', found: '7189057'