QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187679 | #5738. Square Sum | qzez | RE | 0ms | 3836kb | C++14 | 1.6kb | 2023-09-24 20:28:48 | 2023-09-24 20:28:48 |
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];
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 i=0;i<2;i++){
for(int j=0;j<2;j++){
if(i*i+j*j!=z%4)continue;
int x=i||j;
if(!~res[x])res[x]=solve(i,p,k-2,z/4,x);
ans+=res[x];
}
}
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;
}
}
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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: 3836kb
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: 3836kb
input:
5 1 3
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: -100
Runtime Error
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...