#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
int licz(int n)
{
int ile = 0, d_sq, d;
for (int a = 1; a <= n; a++)
{
for (int b = a; b <= n; b++)
{
//cout << a << ' ' << b << ' ' << 1 << '\n';
d_sq = a*a + b*b + 1;
if (d_sq > n*n) break;
d = sqrt(d_sq);
if (d_sq == d*d)
{
ile++;
//cout << a << ' ' << b << ' ' << 1 << '\n';
}
for (int c = 2; c <= n; c++)
{
//cout << a << ' ' << b << ' ' << c << '\n';
d_sq = a*a + b*b + c*c;
if (d_sq > n*n) break;
d = sqrt(d_sq);
if (d_sq == d*d)
{
ile++;
//cout << a << ' ' << b << ' ' << c << '\n';
}
}
}
}
return ile;
}
int n;
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> n;
cout << licz(n);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int uint; int licz(int n) { int ile = 0, d_sq, d; for (int a = 1; a <= n; a++) { for (int b = a; b <= n; b++) { //cout << a << ' ' << b << ' ' << 1 << '\n'; d_sq = a*a + b*b + 1; if (d_sq > n*n) break; d = sqrt(d_sq); if (d_sq == d*d) { ile++; //cout << a << ' ' << b << ' ' << 1 << '\n'; } for (int c = 2; c <= n; c++) { //cout << a << ' ' << b << ' ' << c << '\n'; d_sq = a*a + b*b + c*c; if (d_sq > n*n) break; d = sqrt(d_sq); if (d_sq == d*d) { ile++; //cout << a << ' ' << b << ' ' << c << '\n'; } } } } return ile; } int n; int main() { ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n; cout << licz(n); return 0; } |
English