// Online C++ compiler to run C++ program online
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<iomanip>
#include<string.h>
#include<exception>
#include<map>
#include<cmath>
#include<unordered_map>
#include<set>
#include<climits>
using namespace std;
// 判断两个数是否互质,即最大公因数是否为1
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
int main() {
int N, M;
cin >> N >> M;
// 由于需要排序,所以还需要一个数据结构
vector<vector<int>> result;
if (N + 2 > M)
{
cout << "NA" << endl;
return 0;
}
for (int i = N; i <= M - 2; ++i)
{
for (int j = i + 1; j <= M - 1; ++j)
{
for (int k = j + 1; k <= M; ++k)
{
if ((1 != gcd(k, j)) || (1 != gcd(k, i)) || (1 != gcd(j, i)))
continue;
if (k * k != (i * i + j * j))
continue;
result.push_back({ i, j, k });
}
}
}
if (result.size() == 0) {
cout << "NA" << endl;
return 0;
}
for (auto x : result) {
cout << x[0] << " " << x[1] << " " << x[2] << endl;
}
return 0;
}
华为OD机试-勾股数元组
最新推荐文章于 2023-07-05 09:50:22 发布