QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#490301#5738. Square Sumucup-team1525#WA 15ms3880kbC++201.2kb2024-07-25 14:22:382024-07-25 14:22:40

Judging History

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

  • [2024-07-25 14:22:40]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3880kb
  • [2024-07-25 14:22:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
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};
}
int calc(int p,int k,int r){
    int 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);
    }
}
int work(int z){
    int 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("%d ",work(z));
    }
    puts("");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3808kb

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: 3880kb

input:

5 1
3

output:

4 

result:

ok 1 number(s): "4"

Test #4:

score: -100
Wrong Answer
time: 15ms
memory: 3788kb

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 -897581056 1698693120 0 1698693120 1698693120 1698693120 1698693120 1698693120 1698693120 30888000 1698693120 1698693120 1698693120 -897581056 1698693120 1698693120 30888000 30888000 1698693120 0 30888000 1698693120 30888...

result:

wrong answer 9th numbers differ - expected: '3397386240', found: '-897581056'