QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#287329 | #7315. Line Counting | yyandy | WA | 59ms | 42324kb | C++14 | 1.5kb | 2023-12-20 11:43:08 | 2023-12-20 11:43:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Lim=1000000,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;
inline int solve(unsigned int x,int type){
if(x<=Lim)return F[type][x];
if(u.find(x)!=u.end())return u[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[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*n*(n+1)/2%md;
int S3=3ll*n*(n+1)/2%md,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';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 41688kb
input:
2 3 5
output:
3 9 51
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 48ms
memory: 41756kb
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: 59ms
memory: 41620kb
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: 51ms
memory: 39820kb
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: 28ms
memory: 42152kb
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: 15ms
memory: 42324kb
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: -100
Wrong Answer
time: 58ms
memory: 41120kb
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:
913060559 633367694 352108099 746249800 572815473 139730501 880050253 539360647 329448068 904878768 882809893 506003358 655238550 897801410 735434198 218462638 656716790 694216194 361316031 90746221 347491392 159762859 569385812 630673199 710848273 565700189 471329791 751886686 658811596 611778926 9...
result:
wrong answer 1st lines differ - expected: '247564690', found: '913060559'