QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187195#3853. Lines in a gridFlying2018#WA 239ms332980kbC++142.8kb2023-09-24 15:18:572023-09-24 15:18:57

Judging History

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

  • [2023-09-24 15:18:57]
  • 评测
  • 测评结果:WA
  • 用时:239ms
  • 内存:332980kb
  • [2023-09-24 15:18:57]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long
const int mod=1000003,N=10000010;
int p[N/10],mu[N],pt,s0[N],s1[N],s2[N];bool pr[N];
void posi(int &x){x=x<0?x+mod:x;}
void init(int n=N-10)
{
    mu[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(!pr[i]) p[++pt]=i,mu[i]=-1;
        for(int j=1;j<=pt && i*p[j]<=n;j++)
        {
            pr[i*p[j]]=true;
            if(i%p[j]==0){mu[i*p[j]]=0;break;}
            else mu[i*p[j]]=-mu[i];
        }
    }
    for(int i=1;i<=n;i++)
    {
        s0[i]=(s0[i-1]+mu[i])%mod;
        s1[i]=(s1[i-1]+i*mu[i])%mod;
        s2[i]=(s2[i-1]+1ll*i*i*mu[i])%mod;
        posi(s0[i]),posi(s1[i]),posi(s2[i]);
    }
}
int calc(int x){return 1ll*x*(x+1)/2;}
int solve0(int n,int m)
{
    int ans=0;
    if(n>m) swap(n,m);
    for(int l=1,r;l<=n;l=r+1)
    {
        r=min(n/(n/l),m/(m/l));
        ans=(ans+1ll*(n/l)*(m/l)%mod*(s0[r]-s0[l-1]))%mod;
    }
    return ans;
}
int solve1(int n,int m)
{
    int ans=0;
    if(n>m) swap(n,m);
    for(int l=1,r;l<=n;l=r+1)
    {
        r=min(n/(n/l),m/(m/l));
        ans=(ans+1ll*(1ll*(m/l)*calc(n/l)+1ll*(n/l)*calc(m/l))%mod*(s1[r]-s1[l-1]))%mod;
    }
    return ans;
}
int solve2(int n,int m)
{
    int ans=0;
    if(n>m) swap(n,m);
    for(int l=1,r;l<=n;l=r+1)
    {
        r=min(n/(n/l),m/(m/l));
        ans=(ans+1ll*calc(n/l)*calc(m/l)%mod*(s2[r]-s2[l-1]))%mod;
    }
    return ans;
}
int brute(int n)
{
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            for(int x=1;i+x<=n;x++)
                for(int y=1;j+y<=n;y++) if(__gcd(x,y)==1)
                {
                    if(i-x>=1 && j-y>=1) continue;
                    ++ans;
                }
        }
    // for(int i=1;i<=n;i++)
    //     for(int j=1;j<=n;j++) if(__gcd(i,j)==1)
    //     {
    //         if(i<=n/2 && j<=n/2) ans=(ans+(i+j)*n-3*i*j)%mod;
    //         else ans=(ans+(n-i)*(n-j))%mod;
    //     }
    posi(ans);
    return ans*2%mod;
}
int part1(int n)
{
    int r1=n*solve1(n/2,n/2)%mod;
    int r2=3ll*solve2(n/2,n/2)%mod;
    return (r1-r2+mod)*2ll%mod;
}
int subcalc(int n0,int n,int m)
{
    return (1ll*n0*n0%mod*solve0(n,m)-1ll*n0*solve1(n,m)%mod+solve2(n,m)%mod+mod)%mod;
}
int part2(int n)
{
    int r1=subcalc(n,n/2,n/2);
    int r2=subcalc(n,n,n);
    return (r2-r1+mod)*2ll%mod;
}
signed main()
{
    init();
    int T;scanf("%lld",&T);
    while(T --> 0)
    {
        int n;scanf("%lld",&n);
        if(n==1){puts("0");continue;}
        // int res=brute(n);
        int res2=(part1(n)+part2(n))%mod;
        posi(res2);
        // printf("%d\n",(res+2*n)%mod);
        printf("%lld\n",(res2+2*n)%mod);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 135ms
memory: 331532kb

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: 133ms
memory: 332980kb

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: 239ms
memory: 332392kb

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:

49139
697017
148116
178716
839167
553513
757537
959588
141693
323756
383819
275064
142009
92081
720399
664424
245709
240556
713653
723183
401597
799576
533392
7506
140751
872949
458048
312216
676137
729936
131310
977071
364496
909130
288530
848531
492991
367786
19814
719699
402883
889192
232586
3145...

result:

wrong answer 1st lines differ - expected: '546070', found: '49139'