QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293218#3853. Lines in a gridLaStataleBlueTL 530ms42684kbC++231.5kb2023-12-29 00:43:562023-12-29 00:43:56

Judging History

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

  • [2023-12-29 00:43:56]
  • 评测
  • 测评结果:TL
  • 用时:530ms
  • 内存:42684kb
  • [2023-12-29 00:43:56]
  • 提交

answer

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

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

long long sum(long long x,long long n){
    long long num = n/x;
    return (num*x+x)*num/2ll;
}

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

long long xtimesy(long long n){
    long long res=0;
    
    for(long long i=1;i<=n;i++){
        res+=mob[i]*sum(i,n)%mod*sum(i,n)%mod;
        res%=mod;
    }
    
    return res;
}

long long coprimepair(long long n){
    long long res=0;
    
    for(int i=1;i<=n;i++){
        res+=mob[i]*(n/i)*(n/i)%mod;
        res%=mod;
    }
    
    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;
    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;
    }
    
    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: 502ms
memory: 42684kb

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: 530ms
memory: 42460kb

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
Time Limit Exceeded

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:


result: