码迷,mamicode.com
首页 > 其他好文 > 详细

P1586 四方定理

时间:2019-07-29 10:04:31      阅读:108      评论:0      收藏:0      [点我收藏+]

标签: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 100t100),接下来tt行,每行一个正整数nn(n\le 32768n32768)。

输出格式

对于每个正整数nn,输出方案总数。

输入输出样例

输入 #1
1
2003
输出 #1
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;
}

  

P1586 四方定理

标签:algo   四方定理   sub   输入格式   bottom   接下来   while   marked   button   

原文地址:https://www.cnblogs.com/xiongchongwen/p/11261664.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!