QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#490303#5738. Square Sumucup-team1525#WA 17ms3948kbC++201.2kb2024-07-25 14:24:392024-07-25 14:24:39

Judging History

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

  • [2024-07-25 14:24:39]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3948kb
  • [2024-07-25 14:24:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5;
int m,q;
int tot;
pair<int,int> d[30];
void prep(){
    for(int i=2;i*i<=m;i++)
        if(m%i==0){
            tot++; d[tot].first=i;
            while(m%i==0){
                d[tot].second++;
                m/=i;
            }
        }
    if(m>1)
        d[++tot]={m,1};
}
ll calc(int p,int k,int r){
    ll pk=1; for(int i=0;i<k;i++) pk*=p;
    r%=pk;
    if(p==2){
        if(r==0) return pk;
        if(r==(pk>>1)) return pk;
        for(int i=0;r>>i;i++)
            if((r>>i&1)&&((r>>i+1)&1)) return 0;
        return pk*2;
    }
    if(p%4==3){
        if(r==0) return k&1?pk/p:pk;
        int c=0;
        for(;r%p==0;r/=p) c++;
        return c&1?0:pk/p*(p+1);
    }
    if(p%4==1){
        if(r==0) return pk/p*((k+1)*(p-1)+1);
        if(r%p==0) return pk/p*(p-1)*2;
        return pk/p*(p-1);
    }
}
ll work(int z){
    ll ans=1;
    for(int i=1;i<=tot;i++)
        ans*=calc(d[i].first,d[i].second,z);
    return ans;
}
int main(){
    scanf("%d %d",&m,&q);
    prep();
    while(q--){
        int z; scanf("%d",&z);
        printf("%lld ",work(z));
    }
    puts("");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3948kb

input:

3 3
0 1 2

output:

1 4 4 

result:

ok 3 number(s): "1 4 4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

4 4
0 1 2 3

output:

4 8 4 0 

result:

ok 4 number(s): "4 8 4 0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

5 1
3

output:

4 

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 15ms
memory: 3876kb

input:

735134400 100000
4 4 1 2 3 4 4 4 5 4 3 4 1 1 1 1 2 0 1 4 4 5 4 1 0 0 1 3 0 4 0 5 3 0 3 0 5 4 0 0 3 2 5 3 2 4 3 4 2 1 3 3 2 2 2 3 1 0 1 2 3 4 3 5 4 4 0 1 5 2 2 3 3 2 4 3 5 5 1 3 1 1 4 3 4 3 4 5 2 4 1 3 2 0 5 0 0 5 5 1 2 0 3 4 0 4 1 0 1 4 5 5 3 1 3 0 3 5 0 4 2 0 4 0 0 0 4 0 2 2 2 4 5 3 0 2 0 4 1 4 1 2...

output:

1698693120 1698693120 1698693120 1698693120 0 1698693120 1698693120 1698693120 3397386240 1698693120 0 1698693120 1698693120 1698693120 1698693120 1698693120 1698693120 30888000 1698693120 1698693120 1698693120 3397386240 1698693120 1698693120 30888000 30888000 1698693120 0 30888000 1698693120 30888...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 13ms
memory: 3812kb

input:

735134400 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 308...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 14ms
memory: 3948kb

input:

536870912 100000
1 0 2 4 3 1 3 5 5 1 0 2 1 1 1 0 4 2 4 1 3 2 1 4 3 2 1 2 4 0 4 2 2 1 5 4 1 5 3 0 2 3 4 4 3 4 2 1 2 5 2 1 5 3 1 3 3 0 0 4 3 4 0 4 2 0 5 2 0 3 1 0 0 1 5 5 5 5 5 1 5 3 1 2 4 1 3 3 2 0 2 0 5 1 0 2 1 2 5 2 5 4 4 3 0 3 3 5 4 3 3 2 0 2 1 2 0 1 4 1 1 4 2 4 1 2 4 4 4 2 3 4 5 5 5 4 3 5 5 2 1 5...

output:

1073741824 536870912 1073741824 1073741824 0 1073741824 0 1073741824 1073741824 1073741824 536870912 1073741824 1073741824 1073741824 1073741824 536870912 1073741824 1073741824 1073741824 1073741824 0 1073741824 1073741824 1073741824 0 1073741824 1073741824 1073741824 1073741824 536870912 1073741824...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 9ms
memory: 3860kb

input:

536870912 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 ...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 15ms
memory: 3876kb

input:

536870912 100000
268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268...

output:

536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 ...

result:

ok 100000 numbers

Test #9:

score: -100
Wrong Answer
time: 17ms
memory: 3876kb

input:

536870912 100000
504070704 500101584 484480320 75189632 133364432 237444928 506874208 477655312 261146688 36394912 312952944 260479168 77969872 60413040 249853392 288067360 129948656 311385424 444949024 339508400 62885472 368704208 379750624 528964784 158077280 415604832 393291776 342918080 20621644...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 2nd numbers differ - expected: '1073741824', found: '0'