QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#823142 | #8980. Prime Game | jiangzhihui# | AC ✓ | 644ms | 63400kb | C++14 | 1.3kb | 2024-12-20 19:45:56 | 2024-12-20 19:45:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e6+5;
int a[maxn];
vector<int> t[maxn];//质数出现的位置
signed main(){
//保证只被最小质因子筛去
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
vector<bool> vis(1000000+1);
vector<int> prm;//1e6以内的质数
for(int i=2;i<=1000000;i++){
if(!vis[i])prm.push_back(i);
for(int j=0;j<prm.size();j++){
if(1ll*prm[j]*i>1000000)break;
vis[i*prm[j]]=true;
if(i%prm[j]==0)break;
}
}
for(int i=1;i<=n;i++){
int x=a[i];
for(int j=0;prm[j]*prm[j]<=a[i];j++){
if(x%prm[j]==0){
t[prm[j]].push_back(i);
while(x%prm[j]==0)x/=prm[j];
}
}
if(x>1)t[x].push_back(i);
}
// for(int i=0;i<30;i++){
// for(int j=0;j<t[prm[i]].size();j++)
// cout<<prm[i]<<":"<<t[prm[i]][j]<<":"<<a[t[prm[i]][j]]<<":"<<n-t[prm[i]][j]+1<<endl;
// cout<<"--------------"<<endl;
// }
int ans=0;
for(int i=0;i<prm.size();i++){
int x=prm[i];
for(int j=0;j<t[x].size();j++){
int l=t[x][j];
if(j!=0)l-=t[x][j-1];
ans+=l*(n-t[x][j]+1);
}
}
cout<<ans<<endl;
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 29168kb
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: 11ms
memory: 29320kb
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: 7ms
memory: 28100kb
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: 11ms
memory: 29220kb
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: 11ms
memory: 29692kb
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: 7ms
memory: 29000kb
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: 0
Accepted
time: 644ms
memory: 62956kb
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:
18165930450502454
result:
ok single line: '18165930450502454'
Test #8:
score: 0
Accepted
time: 636ms
memory: 62436kb
input:
1000000 860893 478239 681225 316962 864363 182240 65645 99710 897667 169988 386819 414326 898438 234948 471033 625497 483280 970391 753335 896414 967508 17677 674487 314514 188988 903881 136481 368362 590201 721042 955555 642186 413919 122356 596499 976487 942011 597783 913610 372527 494394 887475 7...
output:
18157576058820902
result:
ok single line: '18157576058820902'
Test #9:
score: 0
Accepted
time: 621ms
memory: 63400kb
input:
1000000 682691 914940 224876 701940 259190 703453 724562 125315 610833 651499 467061 312338 54505 315289 981009 354026 537801 393078 519883 575281 683896 270054 586054 950662 604015 318960 489395 436515 483899 882912 327692 406859 315828 620090 574217 242046 826953 602965 805930 547303 601515 464773...
output:
18197740784667470
result:
ok single line: '18197740784667470'
Test #10:
score: 0
Accepted
time: 642ms
memory: 62872kb
input:
1000000 755948 926490 454109 714178 831604 648864 893662 85154 458838 730588 962865 451849 942414 234072 935713 940369 883279 316863 556822 376075 542691 354956 197948 253337 97937 264721 772598 376623 487324 382703 42608 716592 777937 485770 742000 63275 113282 257134 127586 656057 475626 670569 77...
output:
18151924609137894
result:
ok single line: '18151924609137894'
Extra Test:
score: 0
Extra Test Passed