QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188110 | #5738. Square Sum | qzez | WA | 17ms | 3832kb | C++14 | 1.9kb | 2023-09-25 15:07:53 | 2023-09-25 15:07:53 |
Judging History
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=!x;y<pw[i][k];y++){
if((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?G(i,p,k-2,z/p/p)*p*p:0);
}
ll solve(int i,int p,int k,int z){
if(p==2){
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++){
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: 1ms
memory: 3772kb
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: 3756kb
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: 3832kb
input:
5 1 3
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: -100
Wrong Answer
time: 17ms
memory: 3804kb
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:
2548039680 2548039680 1698693120 1698693120 0 2548039680 2548039680 2548039680 3397386240 2548039680 0 2548039680 1698693120 1698693120 1698693120 1698693120 1698693120 0 1698693120 2548039680 2548039680 3397386240 2548039680 1698693120 0 0 1698693120 0 0 2548039680 0 3397386240 0 0 0 0 3397386240 2...
result:
wrong answer 1st numbers differ - expected: '1698693120', found: '2548039680'