QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187461#3853. Lines in a gridCometoTraval#WA 161ms281476kbC++142.2kb2023-09-24 17:33:442023-09-24 17:33:44

Judging History

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

  • [2023-09-24 17:33:44]
  • 评测
  • 测评结果:WA
  • 用时:161ms
  • 内存:281476kb
  • [2023-09-24 17:33:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e7;
const int mo=100003;
typedef long long ll;
ll mu[10000010],mu1[maxn+10],mu2[maxn+10];
int prime[maxn+10],flag[maxn+10];
int main()
{
    mu[1]=1;
    int cnt=0;
    flag[1]=1;
    for (int i=2;i<=maxn;i++)
    {
        if (!flag[i]) prime[++cnt] = i,mu[i]=-1;
        for (int j=1;j<=cnt;j++)
        {
            if (i*prime[j] > maxn) break;
            flag[i*prime[j]] =1;
            if (i%prime[j]==0)
            {
                mu[i*prime[j]]=0;
                break;
            }
            mu[i*prime[j]] = -mu[i];
        }
    }
    for (int i=1;i<=maxn;i++)
    {
        mu1[i]=mu[i]*i%mo;
        mu2[i]=(ll)mu[i]*i*i%mo;
    }
    for (int i=2;i<=maxn;i++)
    {
        mu[i]=(mu[i-1]+mu[i]+mo)%mo;
        mu1[i]=(mu1[i-1]+mu1[i]+mo)%mo;
        mu2[i]=(mu2[i-1]+mu2[i]+mo)%mo;
    }
    int q;
    scanf("%d",&q);
    while (q--)
    {
        int n;
        scanf("%d",&n);
        if (n==1)
        {
            puts("0");
            continue;
        }
        ll ans=0;
        int r;
        for (int l=1;l<=n;l=r+1)
        {
            int now=n/l;
            r=n/now;
            ll tmp=(ll)n*n%mo*(mu[r]-mu[l-1]+mo)%mo;
            tmp=tmp*now%mo*now%mo;
            (ans+=tmp)%=mo;
            tmp=n*now%mo*now%mo*(now+1)%mo*(mu1[r]-mu1[l-1]+mo)%mo;
            ans=(ans-tmp+mo)%mo;
            tmp=(ll)now*(now+1)/2;
            tmp%=mo;
            tmp=tmp*tmp%mo;
            tmp=tmp*(mu2[r]-mu2[l-1]+mo)%mo;
            ans=(ans+tmp)%mo;
        }
        
        for (int l=1;l<=n/2;l=r+1)
        {
            int now=(n/2)/l;
            r=(n/2)/now;
            ll tmp=(ll)n*n%mo*(mu[r]-mu[l-1]+mo)%mo;
            tmp=tmp*now%mo*now%mo;
            ans=(ans-tmp+mo)%mo;
            tmp=n*now%mo*now%mo*(now+1)%mo*(mu1[r]-mu1[l-1]+mo)%mo;
            ans=(ans+tmp*2%mo+mo)%mo;
            tmp=(ll)now*(now+1)/2;
            tmp%=mo;
            tmp=tmp*tmp%mo;
            tmp=tmp*(mu2[r]-mu2[l-1]+mo)%mo;
            ans=(ans-tmp*4%mo+mo)%mo;
        }
        printf("%lld\n",((ans+n)*2)%mo);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 161ms
memory: 281432kb

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: 155ms
memory: 281476kb

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
4371
21029
39963
60633
84463
9938
39044
70582
5469
42471
83361
27008
75818
27265
83323
42882
8777
77891
53998
34577
21044
11335
9958
13573
25728
42475
67206
98081
39617
86516
433...

result:

wrong answer 26th lines differ - expected: '104374', found: '4371'