QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187229#3853. Lines in a griducup-team1209#WA 152ms172408kbC++171.9kb2023-09-24 15:39:402023-09-24 15:39:40

Judging History

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

  • [2023-09-24 15:39:40]
  • 评测
  • 测评结果:WA
  • 用时:152ms
  • 内存:172408kb
  • [2023-09-24 15:39:40]
  • 提交

answer

#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
using ll = long long ; 
cs int N = 1e7 + 5; 
cs int mod = 1e6 + 3; 
int Q;
vector <int> prm; 
bool ex[N];
int phi[N];
int s1[N], s2[N], s3[N];
void Add(int &x, int y) {
    x += y;
    x = x % mod; 
}
void Dec(int &x, int y) {
    y = y % mod; 
    x = x % mod; 
    x = (x - y + mod) % mod; 
}
void init(int n) {
    phi[1] = 1;
    for(int i = 2; i <= n; i++) {
        if(!ex[i]) prm.pb(i), phi[i] = i - 1; 
        for(int x : prm) {
            if(x * i > n) break;
            ex[x * i] = 1; 
            if(i % x == 0) {
                phi[i * x] = phi[i] * x; 
                break;
            }
            phi[i * x] = phi[i] * (x - 1);
        }
    }
    for(int i = 1; i <= n; i++) {
        s1[i] = phi[i] % mod; 
        Add(s1[i], s1[i - 1]);
        s2[i] = (1ll * i * phi[i] + 1ll * i * phi[i] / 2) % mod;  
        Add(s2[i], s2[i - 1]);
        s3[i] = (1ll * i * phi[i] / 2) % mod * i % mod;
        Add(s3[i], s3[i - 1]);
    }
}
int S1(int n) {
    return (2ll * s1[n] - 1 + mod) % mod;
}
int S2(int n) {
    return (2ll * s3[n] + 1) % mod; 
}
int S3(int n) {
    return (2ll * s2[n]) % mod; 
}
int main() {
    #ifdef zqj
    freopen("1.in","r",stdin);
    #endif
    cin >> Q; 
    init(1e7);
    for(int i = 1; i <= Q; i++) {
        int n; 
        scanf("%d", &n);
        if(n == 1) {
            cout << 0 << '\n';
            continue; 
        }
        int ans = 1ll * n * n % mod * S1(n - 1) % mod; 
        Add(ans, S2(n - 1));
        Dec(ans, n * S3(n - 1) % mod);
        
        Dec(ans, 1ll * n * n % mod * S1((n - 1) / 2) % mod); 
        Dec(ans, 4ll * S2((n - 1) / 2) % mod);
        Add(ans, 2ll * n * S3((n - 1) / 2) % mod); 
        ans = 2ll * (ans + n) % mod; 
        cout << ans << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 152ms
memory: 171900kb

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: 140ms
memory: 171904kb

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: 151ms
memory: 172408kb

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:

810739
999772
599267
770853
937426
969204
543847
757718
395713
939533
290857
508399
122495
896124
736345
74202
214375
147594
900135
92018
971594
684474
553366
333519
928564
857890
586930
252832
199278
944086
536681
512032
128666
255825
793944
657026
933822
446860
451780
950124
618533
657817
601042
3...

result:

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