QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187200 | #3853. Lines in a grid | szhlg# | WA | 149ms | 331420kb | C++14 | 1.4kb | 2023-09-24 15:24:51 | 2023-09-24 15:24:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){
int f = 1,x = 0;
char c = getchar();
while(c > '9' || c < '0'){
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9'){
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const int maxn = 10000005;
int ff[maxn];
int miu[maxn],sum[maxn];
bool vis[maxn];
int su[2000005],cnt;
const int mod = 1000003;
int summ[maxn];
void init(int nn)
{
for(int i=1;i<=nn;++i) ff[i] = i * i % mod * (i + 1) % mod;
miu[1] = 1;
for(int i=2;i<=nn;++i){
if(!vis[i]){
cnt ++;
su[cnt] = i;
miu[i] = -1;
}
for(int j=1;j<=cnt && su[j] * i <= nn;++j){
vis[i * su[j]] = 1;
miu[i*su[j]] = miu[i] * miu[su[j]];
if(i % su[j] == 0){
miu[i * su[j]] = 0;
break;
}
}
}
for(int i=1;i<=nn;++i) sum[i] = sum[i-1] + miu[i];
for(int i=1;i<=nn;++i) summ[i] = summ[i-1] + miu[i] * i,summ[i] %= mod;
}
signed main()
{
init(maxn - 5);
int q = read();
while(q != 0){
--q;
int n = read();
int ans = 0;
int r = 0;
--n;
for(int l = 1;l <= n;l = r + 1)
{//n/i = n/l
r = n/(n/l);
ans += (sum[r] - sum[l-1]) * (2 * n + 1) % mod * (n/l) % mod * (n/l) % mod;
ans %= mod;
int d = n/l;
ans -= ff[n/l] * (summ[r] - summ[l-1]) % mod;
ans %= mod;
}
ans *= 2; ans %= mod;
++n;
if(n != 1) ans += 2 * n;
ans %= mod;
ans += mod;
ans %= mod;
printf("%lld\n",ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 149ms
memory: 331420kb
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'