QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#287331 | #7315. Line Counting | yyandy | WA | 87ms | 59116kb | C++14 | 1.5kb | 2023-12-20 11:50:27 | 2023-12-20 11:50:28 |
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*(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';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 58896kb
input:
2 3 5
output:
3 9 51
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 87ms
memory: 58280kb
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: 43ms
memory: 57132kb
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: 67ms
memory: 59116kb
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: -100
Wrong Answer
time: 40ms
memory: 58856kb
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:
956788319 821462154 802394992 382456956 557499748 842554994 98371661 776234230 621058750 938755390 6908928 912081970 953073050 40100009 629471216 14392438 584441305 322571684 540699376 420457389 250354958 907697005 365949593 827942648 137127767 770771271 826608809 899147263 870728797 382260903 81220...
result:
wrong answer 1st lines differ - expected: '598795826', found: '956788319'