QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#197993 | #3853. Lines in a grid | Forever_Young# | WA | 302ms | 359960kb | C++14 | 3.4kb | 2023-10-02 23:17:01 | 2023-10-02 23:17:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long double D;
typedef pair<int, int> pii;
typedef long long LL;
const int inf = 1e9 + 7;
const int mod = 1000003;
const int N = 10000011;
const int L = 10000000;
int np = 0;
int primes[N], f[N], mu[N], smu[N], smu1[N], smu2[N], s2u[N], s2u1[N], s2u2[N], mnp[N], s2[N];
LL calc(int n) {
return (1ll + n) * n / 2 % mod * (((1ll + n) * n / 2) % mod) % mod;
}
LL integral(LL L, LL R, LL C2, LL C1, LL C0) {
//cout << L << ' ' << R << ' ' << C2 << ' ' << C1 << ' ' << C0 << endl;
LL res = (smu2[R] - smu2[L - 1]) * C2 % mod + (smu1[R] - smu1[L - 1]) * C1 % mod + (smu[R] - smu[L - 1]) * C0 % mod;
//cout << res << endl;
return (res % mod + mod) % mod;
}
LL integral2(LL L, LL R, LL C2, LL C1, LL C0) {
LL res = (s2u2[R] - s2u2[L - 1]) * C2 % mod + (s2u1[R] - s2u1[L - 1]) * C1 % mod + (s2u[R] - s2u[L - 1]) * C0 % mod;
return (res % mod + mod) % mod;
}
int solve(int n) {
if(n == 0) return 0;
int res = 0;
int i = 1;
for(;;) {
int div = n / i;
int nxt = n / div + 1;
//cout << n << ' ' << i << ' ' << nxt << endl;
LL A = (div + 1) * div / 2 % mod;
LL B = (div - 1) * div / 2 % mod;
LL X = (((div + 1) * B - div * A) % mod + mod) % mod;
LL Y = (n + 1) * (A - B) % mod;
//cout << X << ' ' << Y << endl;
res = (res + integral(i, nxt - 1, X * X % mod, 2 * X * Y % mod, Y * Y % mod)) % mod;
//cout << "res = " << res << endl;
res = (res - integral2(i, nxt - 1, X * X % mod, 2 * X * Y % mod, Y * Y % mod) + mod) % mod;
//cout << calc(div) << ' ' << (smu[nxt - 1] - smu[i - 1]) << endl;
i = nxt;
if(i > n) break;
}
//cout << "s" << n << ' ' << res << endl;
return res;
}
int main() {
mu[1] = 1;
primes[0] = inf;
fill(f + 2, f + L + 1, true);
for(int i = 2; i <= L; i++) {
if(f[i]) {
primes[++np] = i;
mnp[i] = np;
mu[i] = -1;
}
for(int j = 1; j <= np && primes[j] * i <= L && i % primes[j - 1]; j++) {
f[primes[j] * i] = false;
mnp[primes[j] * i] = j;
if(mnp[primes[j] * i] == mnp[i]) {
mu[primes[j] * i] = 0;
}else {
mu[primes[j] * i] = -1 * mu[i];
}
}
}
int cnt = 0;
for(int i = 1; i <= L; i++) {
//if(i <= 10) printf("%d %d %d\n", i, mu[i], smu[i]);
smu[i] = (smu[i - 1] + mu[i] + mod) % mod;
smu1[i] = (smu1[i - 1] + mu[i] * i % mod + mod) % mod;
smu2[i] = (smu2[i - 1] + mu[i] * i * (LL)i % mod + mod) % mod;
int m2 = (i % 2 == 0 ? mu[i / 2] : 0);
s2u[i] = (s2u[i - 1] + m2 + mod) % mod;
s2u1[i] = (s2u1[i - 1] + m2 * i % mod + mod) % mod;
s2u2[i] = (s2u2[i - 1] + m2 * i * (LL)i % mod + mod) % mod;
cnt += mu[i] != 0;
}
//printf("cnt = %d\n", cnt);
//cout << "!" << endl;
int Q;
scanf("%d", &Q);
for(int i = 1; i <= Q; i++) {
int n;
scanf("%d", &n);
n--;
int ans = solve(n);// - solve(n / 2) + mod) % mod;
//cout << "a" << ans << endl;
ans = ans * 2 % mod;
ans = (ans + 2 + n * 2) % mod;
if(n == 0) ans = 0;
printf("%d\n", ans);
/*int a1 = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(__gcd(i, j) == 1) {
a1 += (n - i + 1) * (n - j + 1);
if(n - 2 * i >= 0 && n - 2 * j >= 0) {
a1 -= (n - 2 * i + 1) * (n - 2 * j + 1);
}
}
}
}
a1 = a1 * 2 + 2 + n * 2;
if(n == 0) a1 = 0;
printf("%d\n", a1);
//cout << solve(n) << '?' << solve(n / 2) << endl;
assert(ans == a1);*/
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 192ms
memory: 359960kb
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: 231ms
memory: 359944kb
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: 302ms
memory: 359960kb
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:
4594 181592 284042 264619 916417 92772 67799 493788 53064 82960 26316 344967 607240 964460 153153 657559 105261 437190 400599 353376 638423 394593 527973 851631 987650 272639 460770 279724 649801 180418 211846 52367 581881 739263 496295 433925 506252 544245 327393 859769 433044 362419 302115 427427 ...
result:
wrong answer 1st lines differ - expected: '546070', found: '4594'