【勾股定理】牛客周赛 Round 140 F. 小红的三角形构造
题目
https://ac.nowcoder.com/acm/contest/132940/F
题解
构造勾股数的结论:奇数平方取一半,偶数半方加减一。
参考代码
#include<bits/stdc++.h>
using namespace std;int main() {int T;cin >> T;while (T --) {int x; cin >> x;if (x <= 2) {// 小于 3 的情况无解cout << "No\n";continue;}cout << "Yes\n";if (x & 1) {// 奇数平方取一半long long y = 1LL * x * x;cout << x << " " << y / 2LL << " " << y / 2LL + 1LL << '\n';} else {// 偶数半方加减一long long y = (x / 2LL) * (x / 2LL);cout << x << " " << y + 1LL << " " << y - 1LL << '\n';}}
}
