洛谷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
相关文章推荐
- 洛谷 P1586 四方定理
- 洛谷P1586 四方定理
- 四方定理(洛谷 1586)
- P3367 并查集【模板】 洛谷
- BZOJ5340 & 洛谷4564 & LOJ2552:[CTSC2018]假面——题解
- 洛谷 P1373 小a和uim之大逃离
- 洛谷.3804.[模板]后缀自动机
- BZOJ 1413 [ZJOI2009] [洛谷2599] 取石子游戏 (博弈论 dp )
- 洛谷3823 [NOI2017] 蚯蚓排队 【哈希】
- 洛谷P3120 [USACO15FEB]Cow Hopscotch
- 洛谷 P1022 计算器的改良
- 暴力-洛谷P1463 [SDOI2005]反素数ant
- 洛谷P4013 数字梯形问题(费用流)
- 洛谷 P2330 [SCOI2005] 繁忙的都市
- 洛谷P3674 小清新人渣的本愿(莫队)
- AC自动机-洛谷3121 [USACO15FEB]审查(黄金)Censoring (Gold)
- 【KMP】洛谷P2375 [NOI2014]动物园 题解
- 洛谷 P 3371 单元最短路
- 【洛谷2661】信息传递 强联通分量
- 洛谷 P1262 间谍网络==Codevs 4093 EZ的间谍网络