topic
A right triangle has three sides of A, B, C three integers. The longest side length C is known, find a set B, C, B, and C such that the closest.
( Topic Link )
analysis
Hit the table to find the law.
Or a little of the value of direct enumeration of $ CB $. (B unrealistic since enumeration, enumeration difference is a good idea, ah, learned %%% blog )
Or using Fermat's Last Theorem (a small portion),
When ($ A> 1 $) $ A $ is odd, there is an integer of 1 $ $ CB = solutions that $ A ^ 2 + B ^ 2 = C ^ 2 $;
When an even number $ A $ ($ A> 2 $), the presence of $ CB = an integer such that 2 $ solutions $ A ^ 2 + B ^ 2 = C ^ 2 $.
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll a, b, c; int main() { while(scanf("%lld", &a) == 1) { if(a & 1) { b = (a * a - 1) / 2; c = b + 1; } else { b = (a * a - 4) / 4; c = b + 2; } printf("%lld %lld\n", b, c); } return 0; }
Reference links:
1. https://blog.csdn.net/david_jett/article/details/44750687