您的位置:首页 > 其它

洛谷P1586 四方定理

2017-07-02 16:43 267 查看

P1586 四方定理

题目描述

四方定理是众所周知的:任意一个正整数

#include <bits/stdc++.h>

inline void read(long long &x)
{
x = 0;char ch = getchar();char c = ch;
while(ch > '9' || ch < '0')c = ch, ch = getchar();
while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
if(c == '-')x = -x;
}
const int INF = 0x3f3f3f3f;
const int MAXN = 1 << 15;

long long t,n,dp[MAXN + 10][5];
long long ans;

int main()
{
read(t);
for(;t;--t)
{
ans = 0;
read(n);
for(int i = 0;i * i <= n;i ++)
{
int tmp1 = i * i;
for(int j = i;tmp1 + j * j <= n;j ++)
{
int tmp2 = tmp1 + j * j;
for(int k = j;tmp2 + k * k <= n;k ++)
{
int tmp3 = tmp2 + k * k;
int c = n - tmp3;
if(c < k * k)break;
int m = sqrt(c);
if(m * m == c)ans ++;
}
}
}
printf("%lld\n", ans);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: