四方定理是众所周知的:任意一个正整数 n n n,可以分解为不超过四个整数的平方和。例如: 25 = 1 2 + 2 2 + 2 2 + 4 2 25=1^{2}+2^{2}+2^{2}+4^{2} 25=12+22+22+42,当然还有其他的分解方案, 25 = 4 2 + 3 2 25=4^{2}+3^{2} 25=42+32和 25 = 5 2 25=5^{2} 25=52。给定的正整数 n n n,编程统计它能分解的方案总数。注意: 25 = 4 2 + 3 2 25=4^{2}+3^{2} 25=42+32和 25 = 3 2 + 4 2 25=3^{2}+4^{2} 25=32+42视为一种方案。
第一行为正整数 t t t( t ≤ 100 t\le 100 t≤100),接下来 t t t行,每行一个正整数 n n n( n ≤ 32768 n\le 32768 n≤32768)。
对于每个正整数 n n n,输出方案总数。
1
2003
48
#include
using namespace std;
#define sf(x) scanf("%d",&x);
#define de(x) cout<<x<<" ";
#define Pu puts("");
typedef long long ll;
const int N=4e4+10;
int n,m,ans;
// ll a[N];
int f[N][5];
void init(){
// int t=x/2;
// for(int i=1;i<=t;i++){
// if(i*i==x) a[x]+=a[i];
// else a[x]+=a[i]*a[x-i];
// }
for(int i=1;i<=N;i++){
for(int j=i*i;j<=N;j++){
for(int k=1;k<=4;k++){
f[j][k]+=f[j-i*i][k-1];
}
}
}
}
int main(){
int T;cin>>T;
// a[1]=a[2]=a[3]=1;
// for(int i=4;i<=N;i++){
// init(i);
// }
f[0][0]=1;
init();
while(T--){
sf(n)
ans=0;
for(int i=1;i<=4;i++){
ans+=f[n][i];
}
printf("%d\n",ans);
}
}