QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298228#5062. SquareHJRTL 7ms11972kbC++231.7kb2024-01-05 20:52:552024-01-05 20:52:55

Judging History

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

  • [2024-01-05 20:52:55]
  • 评测
  • 测评结果:TL
  • 用时:7ms
  • 内存:11972kb
  • [2024-01-05 20:52:55]
  • 提交

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){
            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: 0ms
memory: 11972kb

input:

3
2 3 6

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Time Limit Exceeded

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:


result: