QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188119#5738. Square SumqzezWA 18ms4084kbC++142.0kb2023-09-25 15:14:382023-09-25 15:14:38

Judging History

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

  • [2023-09-25 15:14:38]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:4084kb
  • [2023-09-25 15:14:38]
  • 提交

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];
int his[N][N];
ll G(int i,int p,int k,int z){
	if(!k)return 0;
	if(p==2&&k<3){
		// debug(i,p,k,z);
		if(~his[k][z%=pw[i][k+1]])
			return his[k][z];
		int cnt=0;
		for(int x=0;x<pw[i][k];x++){
			for(int y=0;y<pw[i][k];y++){
				if((x%p||y%p)&&(x*x+y*y)%pw[i][k+1]==z)cnt++;
				// debug(x,y,cnt);
			}
		}
		return his[k][z]=cnt;
	}
	if(k==1){
		if(p%4==3){
			if(z%p==0)return 0;
			else return p+1;
		}else{
			if(z%p==0)return 2*p-2;
			else return p-1;
		}
	}
	return G(i,p,k-1,z)*p;
}
ll F(int i,int p,int k,int z){
	if(!k)return z%p==0;
	if(k==1)return G(i,p,k,z)+(z%(p*p)==0);
	return G(i,p,k,z)+(z%(p*p)==0?F(i,p,k-2,z/p/p)*p*p:0);
}
ll solve(int i,int p,int k,int z){
	if(p==2){
		// debug(i,p,k-1,z,F(i,p,k-1,z));
		if(k==1)return F(i,p,k,z);
		else return F(i,p,k-1,z)*p*p;
	}else{
		return F(i,p,k,z);
	}
}
int main(){
	memset(his,-1,sizeof his);
	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]*p[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++){
			// debug(p[i],t[i],x,solve(i,p[i],t[i],x));
			ans*=solve(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: 3864kb

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

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

input:

5 1
3

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 17ms
memory: 3796kb

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: 18ms
memory: 3748kb

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: -100
Wrong Answer
time: 14ms
memory: 4084kb

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 1073741824 1073741824 1073741824 0 1073741824 0 1073741824 1073741824 1073741824 1073741824 1073741824 1073741824 1073741824 1073741824 1073741824 1073741824 1073741824 1073741824 1073741824 0 1073741824 1073741824 1073741824 0 1073741824 1073741824 1073741824 1073741824 1073741824 107374...

result:

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