QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402632 | #3853. Lines in a grid | kevinyang# | WA | 273ms | 315724kb | C++17 | 1.1kb | 2024-05-01 05:12:27 | 2024-05-01 05:12:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e7 + 9;
int phi[N];
void totient() {
for (int i = 1; i < N; i++) phi[i] = i;
for (int i = 2; i < N; i++) {
if (phi[i] == i) {
for (int j = i; j < N; j += i) phi[j] -= phi[j] / i;
}
}
}
int e(int n) {
if (n % 2 == 0) return 0;
return phi[(n - 1) / 2];
}
int R2(int n) {
if (n % 2 == 0) return (n - 1) * phi[n-1];
if (n % 4 == 1) return (n - 1) * phi[(n - 1) / 2];
return 0;
}
const int mod = (int)1e6+3;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
totient();
vector<int> L(N + 1, 0), L1(N + 1, 0), R1(N + 1, 0);
L[0] = 0;
L1[1] = 0;
R1[1] = 0;
for (int n = 2; n <= N; n++) {
R1[n] = R1[n - 1] + 4 * (phi[n - 1] - e(n));
L1[n] = 2 * L[n - 1] - L1[n - 1] + R2(n);
L[n] = 2 * L1[n] - L[n - 1] + R1[n];
R1[n]%=mod;
L1[n]%=mod;
L[n]%=mod;
}
int q;
cin >> q;
while(q--){
int x;
cin >> x;
cout << L[x] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 264ms
memory: 315712kb
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: -100
Wrong Answer
time: 273ms
memory: 315724kb
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 -888638 -790012 -686394 -574236 ...
result:
wrong answer 47th lines differ - expected: '111365', found: '-888638'