QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293221#3853. Lines in a gridLaStataleBlueWA 557ms159836kbC++232.1kb2023-12-29 01:01:032023-12-29 01:01:04

Judging History

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

  • [2023-12-29 01:01:04]
  • 评测
  • 测评结果:WA
  • 用时:557ms
  • 内存:159836kb
  • [2023-12-29 01:01:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1e7+5;
const long long mod = 1e6+3;
int mob[MAXN],pref[MAXN],pref2[MAXN],pref3[MAXN];

long long summob(int l,int r){
    return (pref[r]-pref[l-1])%mod;
}

long long summobi(int l,int r){
    return (pref2[r]-pref2[l-1])%mod;
}

long long summobii(int l,int r){
    return (pref3[r]-pref3[l-1])%mod;
}

long long sum(long long n){
    return (n+1)*n/2ll%mod;
}

long long xplusy(long long n){
    long long res=0;
    
    for(long long i=1;i<=n;i++){
        int last = n/(n/i);
        res+=summobi(i,last)*2ll*sum(n/i)%mod*(n/i)%mod;
        res%=mod;
        
        i=last;
    }
    
    return res;
}

long long xtimesy(long long n){
    long long res=0;
    
    for(long long i=1;i<=n;i++){
        int last = n/(n/i);
        res+=summobii(i,last)*sum(n/i)%mod*sum(n/i)%mod;
        res%=mod;
        
        i=last;
    }
    
    return res;
}

long long coprimepair(long long n){
    long long res=0;
    
    for(int i=1;i<=n;i++){
        int last = n/(n/i);
        res+=summob(i,last)*(n/i)*(n/i)%mod;
        res%=mod;
        
        i=last;
    }
    
    return res;
}

long long f(long long n){
    return (n*xplusy(n/2)%mod)-(3ll*xtimesy(n/2)%mod);
}

long long g(long long n,long long num){
    return (n*n%mod*coprimepair(num)%mod)-(n*xplusy(num)%mod)+xtimesy(num);
}

void solve(){
    long long n;
    cin>>n;
    
    long long ans=0;
    
    if(n>1)ans+=n;
    ans+=f(n);
    ans+=g(n,n-1);
    ans-=g(n,n/2);
    ans*=2;
    
    ans%=mod;
    ans+=mod;
    ans%=mod;
    
    cout<<ans<<"\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    mob[1]=1;
    pref[1]=1;
    pref2[1]=1;
    pref3[1]=1;
    
    for(int i=2;i<MAXN;i++){
        int val = -1-mob[i];
        for(int j=2*i;j<MAXN;j+=i)mob[j]+=val;
        mob[i]=val;
        pref[i]=(pref[i-1]+mob[i])%mod;
        pref2[i]=(pref2[i-1]+mob[i]*i)%mod;
        pref3[i]=(pref3[i-1]+mob[i]*i*i)%mod;
    }
    
    int t=1;
    cin>>t;
    for(int i=1;i<=t;i++)solve();
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 459ms
memory: 159764kb

input:

10
1 2 3 4 5 6 7 8 9 10

output:

0
6
20
62
140
306
536
938
1492
2306

result:

ok 10 lines

Test #2:

score: 0
Accepted
time: 425ms
memory: 159800kb

input:

100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

output:

0
6
20
62
140
306
536
938
1492
2306
3296
4722
6460
8830
11568
14946
18900
23926
29544
36510
44388
53586
63648
75674
88948
104374
121032
139966
160636
184466
209944
239050
270588
305478
342480
383370
427020
475830
527280
583338
642900
708798
777912
854022
934604
21071
111365
209991
313609
425767
5425...

result:

ok 100 lines

Test #3:

score: -100
Wrong Answer
time: 557ms
memory: 159836kb

input:

1000
999000 999001 999002 999003 999004 999005 999006 999007 999008 999009 999010 999011 999012 999013 999014 999015 999016 999017 999018 999019 999020 999021 999022 999023 999024 999025 999026 999027 999028 999029 999030 999031 999032 999033 999034 999035 999036 999037 999038 999039 999040 999041 9...

output:

75882
723760
488206
672039
573943
512442
394080
589794
886686
532715
16194
280162
887036
28787
963571
754363
438612
634826
52236
878525
395982
951755
385869
969389
315391
315603
268369
453890
800047
77996
218479
575913
800782
546780
946543
659774
536330
103514
744545
992568
478024
964333
531026
9042...

result:

wrong answer 1st lines differ - expected: '546070', found: '75882'