标签:algo 四方定理 sub 输入格式 bottom 接下来 while marked button
四方定理是众所周知的:任意一个正整数nn,可以分解为不超过四个整数的平方和。例如:25=1^{2}+2^{2}+2^{2}+4^{2}25=12+22+22+42,当然还有其他的分解方案,25=4^{2}+3^{2}25=42+32和25=5^{2}25=52。给定的正整数nn,编程统计它能分解的方案总数。注意:25=4^{2}+3^{2}25=42+32和25=3^{2}+4^{2}25=32+42视为一种方案。
第一行为正整数tt(t\le 100t≤100),接下来tt行,每行一个正整数nn(n\le 32768n≤32768)。
对于每个正整数nn,输出方案总数。
1 2003
48
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<queue> using namespace std; int f[32770][5]; int n=32768,t,ans; int main(){ scanf("%d",&t); f[0][0]=f[0][0]|1; for(int i=1;i*i<=n;i++){ for(int j=i*i;j<=n;j++){ for(int l=1;l<=4;l++){ f[j][l]+=f[j-i*i][l-1]; } } } while(t--){ ans=0; scanf("%d",&n); for(int i=1;i<=4;i++){ ans+=f[n][i]; } printf("%d\n",ans); } return 0; }
标签:algo 四方定理 sub 输入格式 bottom 接下来 while marked button
原文地址:https://www.cnblogs.com/xiongchongwen/p/11261664.html