Links: https://ac.nowcoder.com/acm/contest/1083/C
Title Description
Given right-angled triangle in which the length of one side of n, is to construct your task remaining two sides, so that it can form three sides of a right triangle.
Enter a description:
An integer n.
Output Description:
The two other edges b, c. The answer is not unique, as long as any set of output that is reasonable, if you can not make construction output -1.
Remarks:
0 <= n-<= 1E9
. 1 <= B, C <= 1e18
n-, B, C are integers
Number Pythagorean:
The first type
When a is greater than one
odd
+ 1 2n, b = 2n² + 2n, c = 2n² + 2n + 1.
A is actually the
number of squares
split into two
consecutive natural numbers
, for example:
When n = 1 (a, b, c) = (3,4,5)
when n = 2 (a, b, c) = (5,12,13)
For n = 3 (a, b, c) = (7,24,25)
……
This is the most classic of a routine, and because of the inevitable two consecutive natural numbers
relatively prime
, so use this routine to get the Pythagorean are all relatively prime.
The second type
2, when a is larger than an even number 2n 4, b = n²-1, c = n² + 1
That is the half of a square, respectively, minus one and plus one, for example:
For n = 3 (a, b, c) = (6,8,10)
when n = 4 (a, b, c) = (8,15,17)
n = 5 when (a, b, c) = (10,24,26)
when n = 6 (a, b, c) = (12,35,37)
#include <iostream> using namespace std; int main() { int n; cin >> n; if(n>1&&n&1) { long long t=(n-1)/2; long long b=2*t*t+2*t; long long c=2*t*t+2*t+1; cout << b << " " << c << endl; } else if(n>=4&&n%2==0) { long long t=n/2; long long b=t*t-1; long long c=t*t+1; cout << b << " " << c << endl; } else cout << -1 << endl; return 0; }