QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#326410#5738. Square Sumushg8877WA 35ms3724kbC++141.2kb2024-02-13 00:10:312024-02-13 00:10:32

Judging History

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

  • [2024-02-13 00:10:32]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:3724kb
  • [2024-02-13 00:10:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
ll pow(int a,int b){ll r=1;while(b--)r=r*a;return r;}
ll g(int p,int k,int z){
	if(k==0) return 0;
	if(k==1){
		if(z) return p-(p%4==1?1:-1);
		else return (p%4==1?2*p-2:0);
	}if(p==2&&k<=3){
		int ans=0;
		for(int i=1;i<(1<<k);i++) for(int j=1;j<(1<<k);j++)
			if(((i&1)||(j&1))&&(i*i+j*j)%(1<<k)==z) ans++;
		return ans;
	}return g(p,k-1,z%pow(p,k-1))*p;
}
ll f(int p,int k,int z){
	if(k==0) return 1;
	else if(p==2&&k<=3){
		int ans=0;
		for(ll i=0;i<(1<<k);i++) for(ll j=0;j<(1<<k);j++)
			if((i*i+j*j)%(1<<k)==z) ans++;
		return ans;
	}else if(k==1){
		if(z) return p-(p%4==1?1:-1);
		else return (p%4==1?2*p-1:1);
	}else return g(p,k,z)+p*p*(z%(p*p)==0?f(p,k-2,z/p/p):0);
}// solve the equivment x^2+y^2==z (mod p^k)
int main(){
	ios::sync_with_stdio(false);
	map<int,int> mp;
	int m,_;
	cin>>m>>_;
	for(int i=2;i*i<=m;i++) if(m%i==0){
		while(m%i==0) mp[i]++,m/=i;
	}
	if(m>1) mp[m]++;
	while(_--){
		ll x,ans=1;cin>>x;
		for(auto p:mp) ans*=f(p.first,p.second,x%pow(p.first,p.second)); 
		cout<<ans<<' ';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3660kb

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

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: 1ms
memory: 3724kb

input:

5 1
3

output:

4 

result:

ok 1 number(s): "4"

Test #4:

score: -100
Wrong Answer
time: 35ms
memory: 3684kb

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:

849346560 849346560 849346560 1698693120 0 849346560 849346560 849346560 3397386240 849346560 0 849346560 849346560 849346560 849346560 849346560 1698693120 30888000 849346560 849346560 849346560 3397386240 849346560 849346560 30888000 30888000 849346560 0 30888000 849346560 30888000 3397386240 0 30...

result:

wrong answer 1st numbers differ - expected: '1698693120', found: '849346560'