4122: GESP C++二级样题_4勾股数
内存限制:128 MB
时间限制:1.000 S
评测方式:文本比较
命题人:
提交:8
解决:6
题目描述
样例输入 复制
5
样例输出 复制
1
提示
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
for (int a = 1; a <= n; a++)
for (int b = a; b <= n; b++) {
int c2 = a * a + b * b;
int c = (int)(sqrt(c2) + 0.5);
if (c > n)
break;
if (c * c == c2)
cnt++;
}
cout << cnt << endl;
return 0;
}