QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#735633#8980. Prime GameWzyTL 9ms12000kbC++141.7kb2024-11-11 21:03:222024-11-11 21:03:29

Judging History

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

  • [2024-11-11 21:03:29]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:12000kb
  • [2024-11-11 21:03:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef pair<char,int> PCI;
typedef pair<int,int> PII;
const int N=1000010,M=2000010;
const int mod=1e9+7;
int INF = 1e9;
int T=1;
int phi[N],st[N],primes[N],cnt;

void init(int n)
{
    phi[1] = 1;
    for (int i = 2; i <= n; i ++ )
    {
        if (!st[i])
        {
            primes[cnt ++ ] = i;
            phi[i] = i - 1;
        }
        for (int j = 0; primes[j] * i <= n; j ++ )
        {
            st[i * primes[j]] = true;
            if (i % primes[j] == 0)
            {
                phi[i * primes[j]] = phi[i] * primes[j];
                break;
            }
            phi[i * primes[j]] = phi[i] * (primes[j] - 1);
        }
    }
}

 
void solve(){
    int n;
    cin>>n;

    vector<int> a(n+10);

    for(int i=0;i<n;i++) cin>>a[i];

    map<int,vector<int>> mp;

    for(int i=0;i<n;i++){
        for(int j=0;primes[j]<=a[i];j++){
            bool sg=true;

            while(a[i]%primes[j]==0){
                if(sg){
                    mp[primes[j]].push_back(i);
                    sg=false;
                }
                a[i]/=primes[j];
            }
        }
    }
    LL res=0;
    for(auto [x,y]:mp){
        for(int i=0;i<y.size();i++){
            //cout<<x<<" "<<y[i]<<endl;
            if(i==y.size()-1) res+=(n-y[i])*(y[i]+1);
            else res+=(y[i+1]-y[i])*(y[i]+1);
        }
    } 


    cout<<res<<endl;
    

}

    
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //int T=1;
    //cin>>T;
    init(N-1);
    while(T--) solve();
 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11780kb

input:

10
99 62 10 47 53 9 83 33 15 24

output:

248

result:

ok single line: '248'

Test #2:

score: 0
Accepted
time: 3ms
memory: 11660kb

input:

10
6 7 5 5 4 9 9 1 8 12

output:

134

result:

ok single line: '134'

Test #3:

score: 0
Accepted
time: 8ms
memory: 11664kb

input:

10
99 62 10 47 53 9 83 33 15 24

output:

248

result:

ok single line: '248'

Test #4:

score: 0
Accepted
time: 8ms
memory: 11976kb

input:

10
692137 743219 52652 45276 492360 972264 988496 117515 917868 423315

output:

521

result:

ok single line: '521'

Test #5:

score: 0
Accepted
time: 4ms
memory: 12000kb

input:

100
408775 951905 198113 227169 170826 717434 172837 379198 720110 733849 256909 997639 834222 642949 317137 409227 410206 641528 625980 937295 557730 566754 910637 716940 949428 513251 236121 195566 241377 442709 617863 89943 809036 620607 976274 444954 341290 780899 673131 169536 855557 140849 834...

output:

255236

result:

ok single line: '255236'

Test #6:

score: 0
Accepted
time: 9ms
memory: 11752kb

input:

100
620478 109788 646916 312450 22667 609293 640239 655905 216968 843038 852594 133249 544178 720291 37881 435654 196271 976771 719580 494391 767626 423169 168736 199494 80683 744612 304689 133336 547615 244143 920884 220033 820152 494269 954687 660735 882144 978008 694034 221928 706590 479076 43374...

output:

245996

result:

ok single line: '245996'

Test #7:

score: -100
Time Limit Exceeded

input:

1000000
709877 145493 170549 915888 2504 680394 758139 24665 365499 242644 535590 994789 297247 518365 834337 852392 945750 480961 126953 485671 11673 262033 473744 199902 743475 91856 394619 779195 616388 60537 756645 570144 510464 285494 932570 298148 627373 110058 469501 686867 559208 82153 90754...

output:


result: