QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287332 | #7315. Line Counting | yyandy | AC ✓ | 194ms | 60188kb | C++14 | 1.5kb | 2023-12-20 11:51:03 | 2023-12-20 11:51:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Lim=1500000,md=1e9+7,inv2=(md+1)/2,inv3=(md+1)/3;
ll F[4][Lim+5];
int p[Lim+5],ph[Lim+5],mu[Lim+5],v[Lim+5],T,n;
unordered_map<unsigned,ll>isval[3];
void Pre(int x){
mu[1]=ph[1]=1;
for(int i=2,cnt=0;i<=x;++i){
if(!v[i]){p[++cnt]=i;mu[i]=-1;ph[i]=i-1;}
for(int j=1,e;(e=p[j]*i)<=x&&j<=cnt;++j)
if(!(i%p[j])){v[e]=1;ph[e]=ph[i]*p[j];break;}else v[e]=1,ph[e]=ph[i]*(p[j]-1),mu[e]=-mu[i];
}
for(int i=1;i<=x;++i)F[0][i]=(F[0][i-1]+ph[i])%md,F[1][i]=(F[1][i-1]+1ll*ph[i]*i)%md,F[2][i]=(F[2][i-1]+1ll*ph[i]*i%md*i)%md;
}
inline int pw1(int x){
return 1ll*x*(x+1)/2%md;
}
inline int pw2(int x){
return 1ll*x*(x+1)/2%md*(2ll*x+1)%md*inv3%md;
}
unordered_map<int,int> u[4];
inline int solve(unsigned int x,int type){
if(x<=Lim)return F[type][x];
if(u[type].find(x)!=u[type].end())return u[type][x];
int ans=(type==0)?(pw1(x)):((type==1)?(pw2(x)):(1ll*pw1(x)*pw1(x)%md));
for(int l=2,r;l<=(int)x;l=r+1){
r=x/(x/l);
int tmp=(type==0)?(r-l+1):((type==1)?(pw1(r)-pw1(l-1)):(pw2(r)-pw2(l-1))),res=solve(x/l,type);
ans=(ans-1ll*tmp*res)%md;
}
return u[type][x]=(ans+md)%md;
}
int main(){
Pre(Lim);
while(cin>>n){
if(!n)exit(0);
int val0=solve(n,0),val1=solve(n,1),val2=solve(n,2),val3=solve(n/2,0),val4=solve(n/2,1),val5=solve(n/2,2);
int S2=inv2*3ll%md,S1=inv2*((6ll*n+3)%md)%md,S0=3ll*(1ll*n*(n+1)/2%md)%md;
int S3=S0,S4=(6ll*n+3)%md,S5=6;
cout<<((1ll*S0*val0-1ll*S1*val1+1ll*S2*val2-1ll*S3*val3+1ll*S4*val4-1ll*S5*val5)%md+md)%md<<'\n';
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 21ms
memory: 58956kb
input:
2 3 5
output:
3 9 51
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 39ms
memory: 59112kb
input:
870 189 181 57 621 981 456 620 151 840 898 382 668 612 155 631 254 455 493 287 703 689 182 524 177 514 976 236 692 821 863 706 341 121 327 193 312 977 934 169 75 565 387 4 953 570 174 750 72 172 841 426 107 388 510 21 136 330 308 388 615 592 87 949 688 222 153 80 390 675 340 959 143 54 31 875 357 9 ...
output:
726343250 73489449 61843251 622833 503241635 891215059 475017626 448647350 30023409 442875502 144545713 219959017 382139909 21305960 33321885 63856818 239090232 453401405 380397414 389365605 959694502 881182065 63217506 313245772 56569641 993582171 821671857 178296642 106836475 956928364 686314810 1...
result:
ok 100000 lines
Test #3:
score: 0
Accepted
time: 40ms
memory: 59084kb
input:
1090 1617 1854 1477 1550 1299 1483 1998 1991 1174 1688 1626 1096 1280 1055 1437 1917 1747 1737 1281 1065 1293 1547 1796 1580 1476 1832 1831 1206 1919 1294 1777 1461 1135 1174 1436 1590 1404 1301 1604 1573 1586 1804 1508 1974 1192 1615 1942 1195 1415 1031 1382 1891 1938 1096 1480 1523 1058 1806 1188 ...
output:
597841394 120553089 108789902 601785352 389118461 527988687 40491597 158409207 487434155 451111524 261502861 876020534 386345194 229162233 738189571 362994150 485145587 484914084 423289950 708376770 457245958 547051224 847236827 651113411 631227301 867237522 685479270 283759934 762417876 704730776 4...
result:
ok 100000 lines
Test #4:
score: 0
Accepted
time: 48ms
memory: 59676kb
input:
5423 9250 9195 8674 9394 4907 4389 2029 7884 4493 5480 7308 7916 4711 3102 7795 7882 6590 7651 3760 6599 9072 8945 7570 5260 4275 9376 6258 6075 3410 7209 2380 7289 9269 9536 7894 6629 3882 9591 5561 9556 7710 8098 8926 7404 9399 3310 5096 3706 8737 6753 7753 2707 3691 5517 4568 3241 7701 7651 7970 ...
output:
726344771 813785295 744751059 216922833 987192706 49849548 404837369 894645687 796552929 19589551 622111208 709783835 276066733 41317255 439195998 132008397 403283060 706049449 80411643 378255747 237948467 440828235 621942687 564313980 639191706 531678693 426217298 704958066 674541848 724441086 5670...
result:
ok 100000 lines
Test #5:
score: 0
Accepted
time: 36ms
memory: 59048kb
input:
89299 68762 30308 20225 66534 44065 50896 55224 39111 15013 66996 54474 31504 51071 88011 31007 16635 20799 26003 15195 20700 67554 31010 70960 92532 18363 95234 18235 95762 71755 12810 48335 25459 48993 36585 43503 57705 10028 25970 16351 35631 71266 54156 78402 21397 34595 37727 26317 80777 83559 ...
output:
598795826 986480535 802394992 382456956 11312606 842554994 250525443 371780420 621058750 938755390 7235067 176371258 953073050 666680784 960010593 14392438 584441305 322571684 540699376 420457389 250354958 738778747 365949593 611925674 678571124 770771271 994894346 899147263 856920387 854090672 8122...
result:
ok 36476 lines
Test #6:
score: 0
Accepted
time: 20ms
memory: 59224kb
input:
880756 620758 607287 548801 657988 359444 431439 244916 430597 235538 583516 217235 687817 700140 345345 195573 943926 315272 804084 114312 160751 888124 704255 484390 820531 376914 608617 523197 641070 535443 907350 593731 840307 208363 942629 823747 579993 642401 621034 830518 770911 838113 348756...
output:
15279072 335788811 176262118 952094313 242553672 785959545 206870218 327314805 174795465 192838043 489023696 191479692 830030304 762192179 787623504 356863163 295084128 670874531 504220672 704343478 192607007 902738938 283763116 35241563 927894588 837679768 35671306 930520319 592165180 128588530 462...
result:
ok 3694 lines
Test #7:
score: 0
Accepted
time: 140ms
memory: 59548kb
input:
8812648 4011093 4365659 8628009 3680213 8512170 4370876 2913631 1311961 7238571 3295030 7571293 8594050 7959752 7138707 4330584 8073312 7042578 7918430 1311461 2290168 7693571 7822755 7552668 1024765 5701281 6960436 6960776 6660576 9447617 2103390 7239383 7662002 7297208 3828474 6177779 2533535 8844...
output:
247564690 544608316 754122379 309660989 825840248 333658798 552520716 249721350 309942669 852949824 936202904 200546071 152465453 691489875 433572571 522049805 344385614 94996637 658489139 165889626 926439677 750857026 7058658 29391580 152500700 262696928 192589857 447956007 742381218 277318312 5269...
result:
ok 348 lines
Test #8:
score: 0
Accepted
time: 158ms
memory: 58020kb
input:
17925651 17099467 17071022 18455267 19770802 11726496 19079434 12954713 18280589 17524861 10927015 12122026 19648864 11990243 12826419 19138409 11547988 10582756 14794936 17986087 18557233 14667203 17784377 14526328 19072274 11176824 17343349 19019473 14718197 16061362 12372399 15024988 10410097 164...
output:
505953729 228925608 450991002 967671277 296408004 108976403 55723739 872956044 400382758 199714408 285370245 884022346 192682717 653339133 567644366 570993377 399870773 742471549 67738828 848984948 469192532 533472006 544800258 862858548 382435543 530304879 123531067 495969866 387969592 556305290 16...
result:
ok 133 lines
Test #9:
score: 0
Accepted
time: 186ms
memory: 59008kb
input:
73630685 35776802 88148136 38409603 60248967 46097946 47962168 86725677 97996940 25646464 23044743 55741000 36535510 90374875 98289422 25489366 91804116 45632104 44788552 38850083 84588852 80239605 71342089 34078377 49161097 79211806 79477417 50140785 83544018 72716668 22092811 66429285
output:
8525426 66349269 670843437 197136055 922896471 488855454 908762388 271914616 668608575 214639171 17402897 7667777 162243131 580678438 619456386 580285105 232319960 585292924 567336134 247205933 852239480 188301925 244825340 972096528 820322110 159260480 144044351 425195952 784384546 367257253 443864...
result:
ok 32 lines
Test #10:
score: 0
Accepted
time: 156ms
memory: 58960kb
input:
964719340 618940112
output:
119608550 375017868
result:
ok 2 lines
Test #11:
score: 0
Accepted
time: 171ms
memory: 59232kb
input:
108257656 238411844 518349801 581703611 250359167
output:
915877158 279623775 951282418 532710463 747214368
result:
ok 5 lines
Test #12:
score: 0
Accepted
time: 124ms
memory: 59624kb
input:
1188212174
output:
251777675
result:
ok single line: '251777675'
Test #13:
score: 0
Accepted
time: 186ms
memory: 59560kb
input:
1890656683
output:
612731820
result:
ok single line: '612731820'
Test #14:
score: 0
Accepted
time: 156ms
memory: 59540kb
input:
1593101194
output:
639822401
result:
ok single line: '639822401'
Test #15:
score: 0
Accepted
time: 113ms
memory: 59864kb
input:
1148062054
output:
367813057
result:
ok single line: '367813057'
Test #16:
score: 0
Accepted
time: 194ms
memory: 60188kb
input:
2000000000
output:
831406920
result:
ok single line: '831406920'
Extra Test:
score: 0
Extra Test Passed