QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283824#7315. Line CountingTx_LcyAC ✓241ms131928kbC++143.8kb2023-12-15 15:55:352023-12-15 15:55:36

Judging History

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

  • [2023-12-15 15:55:36]
  • 评测
  • 测评结果:AC
  • 用时:241ms
  • 内存:131928kb
  • [2023-12-15 15:55:35]
  • 提交

answer

//A tree without skin will surely die.
//A man without face is invincible.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sqr(x) ((x)*(x))
#define all(x) (x).begin(),(x).end()
#define Tim ((double)clock()/CLOCKS_PER_SEC)
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
int const maxn=5e6;
int const N=maxn+10;
int const mod=1e9+7;
int const iv2=(mod+1)/2;
int n,iv6,iv4;
inline int qpow(int a,int b){
    int res=1;
    while (b){
        if (b&1) res*=a,res%=mod;
        a*=a,a%=mod,b>>=1;
    }
    return res;
}
inline int phi(int x){
    if (x==1) return 0;
    int ans=x;
    for (int i=2;i*i<=x;++i){
        if (x%i) continue;
        ans/=i,ans*=(i-1);
        while (x%i==0) x/=i;
    }
    if (x^1) ans/=x,ans*=(x-1);
    return ans%mod;
}
int cnt,pai[N],pai2[N],pai3[N],prim[N];
bool vis[N];
inline void init(){
    pai[1]=pai2[1]=pai3[1]=1;
    for (int i=2;i<=maxn;++i){
        if (!vis[i])
            prim[++cnt]=i,pai[i]=i-1,pai2[i]=pai[i]*i%mod,pai3[i]=pai2[i]*i%mod;
        for (int j=1;j<=cnt && prim[j]*i<=maxn;++j){
            vis[prim[j]*i]=1;
            if (i%prim[j]==0){
                pai[i*prim[j]]=pai[i]*prim[j]%mod;
                pai2[i*prim[j]]=pai2[i]*prim[j]%mod*prim[j]%mod;
                pai3[i*prim[j]]=pai3[i]*prim[j]%mod*prim[j]%mod*prim[j]%mod;
                break;
            }
            pai[i*prim[j]]=pai[prim[j]]*pai[i]%mod;
            pai2[i*prim[j]]=pai2[prim[j]]*pai2[i]%mod;
            pai3[i*prim[j]]=pai3[prim[j]]*pai3[i]%mod;
        }
    }
    for (int i=2;i<=maxn;++i)
        pai[i]+=pai[i-1],pai[i]%=mod,
        pai2[i]+=pai2[i-1],pai2[i]%=mod,
        pai3[i]+=pai3[i-1],pai3[i]%=mod;
}
unordered_map<int,int>ans_pai,ans_pai2,ans_pai3;
inline int smphi(int x){
    if (x<=maxn) return pai[x];
    if (ans_pai[x]) return ans_pai[x];
    int ans=x*(x+1)%mod*iv2%mod;
    for (int l=2,r;l<=x;l=r+1){
        r=x/(x/l);
        ans+=mod-((r-l+1)*smphi(x/l)%mod),ans%=mod;
    }
    return ans_pai[x]=ans;
}
inline int smphi1(int x){
    if (x<=maxn) return pai2[x];
    if (ans_pai2[x]) return ans_pai2[x];
    int ans=(x+1)*x%mod*(2*x+1)%mod*iv6%mod;
    for (int l=2,r;l<=x;l=r+1){
        r=x/(x/l);
        ans+=mod-(((l+r)*(r-l+1)/2)%mod*smphi1(x/l)%mod),ans%=mod;
    }
    return ans_pai2[x]=ans;
}
inline int qr(int x){
    return (x+1)*x%mod*(2*x%mod+1)%mod*iv6%mod;
}
inline int smphi2(int x){
    if (x<=maxn) return pai3[x];
    if (ans_pai3[x]) return ans_pai3[x];
    int ans=x*x%mod*(x+1)%mod*(x+1)%mod*iv4%mod;
    for (int l=2,r;l<=x;l=r+1){
        r=x/(x/l);
        ans+=mod-((qr(r)+mod-qr(l-1))%mod*smphi2(x/l)%mod),ans%=mod;
    }
    return ans_pai3[x]=ans;
}
inline int qzphi0(int x){
    if (x==0) return 0;
    return smphi(x)-1;
}
inline int qzphi1(int x){
    if (x==0) return 0;
    return smphi1(x)-1;
}
inline int qzphi2(int x){
    if (x==0) return 0;
    return smphi2(x)-1;
}
void solve(){
    while (cin>>n){
        int ans=2*n-2;
        int nt=qzphi2(n-1),no=qzphi1(n-1),nz=qzphi0(n-1);
        int gt=qzphi2(n/2),go=qzphi1(n/2),gz=qzphi0(n/2);
        nt-=gt,no-=go,nz-=gz;
        ans+=((n*n+n)%mod*nz%mod-(2*n+1)*no%mod+nt)%mod*iv2%mod;
        ans+=((2*n+1)%mod*go%mod-3*gt%mod)*iv2%mod;
        nt=qzphi2(n),no=qzphi1(n),nz=qzphi0(n);
        ans+=((n*n+n)%mod*nz%mod-(2*n+1)*no%mod+nt)%mod;
        ans-=((n*n+n)%mod*gz%mod-(2+4*n)%mod*go%mod+4*gt%mod)%mod;
        ans+=(n*(n-1)/2)%mod;
        if (n/2>=1) ans-=((n-1)*(n-2)/2)%mod;
        ans%=mod,ans+=mod,ans%=mod;
        cout<<ans<<'\n';
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t=1;init();
    iv6=qpow(6,mod-2);
    iv4=qpow(4,mod-2);
    // cin>>t;
    while (t--) solve();
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 100ms
memory: 130080kb

input:

2
3
5

output:

3
9
51

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 115ms
memory: 129900kb

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: 113ms
memory: 129884kb

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: 112ms
memory: 130084kb

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: 107ms
memory: 129832kb

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: 100ms
memory: 130088kb

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: 185ms
memory: 130108kb

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: 232ms
memory: 130172kb

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: 236ms
memory: 129888kb

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: 211ms
memory: 129940kb

input:

964719340
618940112

output:

119608550
375017868

result:

ok 2 lines

Test #11:

score: 0
Accepted
time: 210ms
memory: 131928kb

input:

108257656
238411844
518349801
581703611
250359167

output:

915877158
279623775
951282418
532710463
747214368

result:

ok 5 lines

Test #12:

score: 0
Accepted
time: 184ms
memory: 129980kb

input:

1188212174

output:

251777675

result:

ok single line: '251777675'

Test #13:

score: 0
Accepted
time: 228ms
memory: 129868kb

input:

1890656683

output:

612731820

result:

ok single line: '612731820'

Test #14:

score: 0
Accepted
time: 203ms
memory: 129884kb

input:

1593101194

output:

639822401

result:

ok single line: '639822401'

Test #15:

score: 0
Accepted
time: 189ms
memory: 130108kb

input:

1148062054

output:

367813057

result:

ok single line: '367813057'

Test #16:

score: 0
Accepted
time: 241ms
memory: 129868kb

input:

2000000000

output:

831406920

result:

ok single line: '831406920'

Extra Test:

score: 0
Extra Test Passed