QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187010#3853. Lines in a griducup-team1209#WA 125ms133104kbC++171.4kb2023-09-24 13:54:002023-09-24 13:54:01

Judging History

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

  • [2023-09-24 13:54:01]
  • 评测
  • 测评结果:WA
  • 用时:125ms
  • 内存:133104kb
  • [2023-09-24 13:54:00]
  • 提交

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) {
    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 + 1) * phi[i] + 1ll * i * phi[i] / 2) % mod + mod) % mod;  
        Add(s2[i], s2[i - 1]);
    }
}
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 = 2ll * n * s1[n - 1] % mod; 
        Dec(ans, s2[n - 1] + 1);
        Add(ans, ans);
        Dec(ans, 2 * n - 3);
        Add(ans, n);
        Add(ans, ans);
        cout << ans << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 125ms
memory: 133104kb

input:

10
1 2 3 4 5 6 7 8 9 10

output:

0
6
20
54
108
210
320
522
744
1050

result:

wrong answer 4th lines differ - expected: '62', found: '54'