QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187681#5738. Square SumqzezWA 11ms3956kbC++141.7kb2023-09-24 20:32:112023-09-24 20:32:12

Judging History

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

  • [2023-09-24 20:32:12]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3956kb
  • [2023-09-24 20:32:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
	cerr<<x<<' ',debug(y...);
}
const int N=30;
int n,m,k;
int p[N],t[N];
vector<int>pw[N];
ll solve(int i,int p,int k,int z,bool tag=0){
	if(!k)return 1;
	if(tag)return pw[i][k];
	if(z%p!=0)return 0;
	return (p*p-1)*solve(i,p,k-1,z/p,1)+solve(i,p,k-1,z/p,0);
}
ll calc(int i,int p,int k,int z){
	if(p==2){
		if(k==1)return 2;
		ll res[2]={-1,-1},ans=0;
		for(int x=0;x<2;x++){
			for(int y=0;y<2;y++){
				if(x*x+y*y!=z%4)continue;
				int t=x||y;
				if(!~res[t])res[t]=solve(i,p,k-2,z/p/p,t);
				ans+=res[t];
			}
		}
		return ans*p*p;
	}
	ll ans=0;
	if(p%4==3){
		if(z%p==0)ans=0;
		else ans=p+1;
	}else{
		if(z%p==0)ans=2*p-2;
		else ans=p-1;
	}
	return ans*solve(i,p,k-1,z/p,1)+(z%p==0?solve(i,p,k-1,z/p,0):0);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=2;i*i<=n;i++){
		if(n%i)continue;
		p[++k]=i;
		for(;n%i==0;n/=i)t[k]++;
	}
	if(n>1){
		p[++k]=n,t[k]=1;
	}
	for(int i=1;i<=k;i++){
		pw[i].assign(t[i]+1,0);
		for(int j=pw[i][0]=1;j<=t[i];j++){
			pw[i][j]=pw[i][j-1]*i;
		}
	}
	// debug("pri",ary(p,1,k));
	// debug("cnt",ary(t,1,k));
	for(int x;m--;){
		scanf("%d",&x);
		ll ans=1;
		for(int i=1;i<=k;i++)ans*=calc(i,p[i],t[i],x);
		printf("%lld%c",ans,"\n "[m>0]);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

5 1
3

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: -100
Wrong Answer
time: 11ms
memory: 3956kb

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:

0 0 28311552 14155776 0 0 0 0 56623104 0 0 0 28311552 28311552 28311552 28311552 14155776 52552500 28311552 0 0 56623104 0 28311552 52552500 52552500 28311552 0 52552500 0 52552500 56623104 0 52552500 0 52552500 56623104 0 52552500 52552500 0 14155776 56623104 0 14155776 0 0 0 14155776 28311552 0 0 ...

result:

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