Pythagorean Triples畢達哥斯拉三角(數學思維+構造)


Description

Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.

For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.

Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.

Katya had no problems with completing this task. Will you do the same?

Input

The only line of the input contains single integer n (1 ≤ n ≤ 109) — the length of some side of a right triangle.

Output

Print two integers m and k (1 ≤ m, k ≤ 1018), such that nm and k form a Pythagorean triple, in the only line.

In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.

Sample Input

Input
3
Output
4 5
Input
6
Output
8 10
Input
1
Output
-1
Input
17
Output
144 145
Input
67
Output
2244 2245

Hint

Illustration for the first sample.

 

  題目意思:給你一條邊,求出另外的兩條邊,使得這三條邊能夠構造出一個直角三角形。
 
 解題思路:首先要明確一點,題目說過如果有多個解,只要輸出一組就可以了,我認為這個要求很關鍵,只要構造出一組解就行,實際上這樣也解放了思維。比如所給的邊,可以是直角邊,也可以是斜邊,但我們知道如果是直角邊那么一定可以找出一組邊與其構成直角三角形;但是如果是斜邊的話,則不一定能夠找出一組邊,所以假定所給的邊為直角邊更好。那么接下來分析:

假設輸入的n是一條直角邊的長度,那么

\

根據平方差公式可得

\

那么,這個時候,我們要求解的就是a,b

要明確,我們只不過要求解一組解即可!在對n^2划分奇偶后,只要構造出整數解即可!

接下來要做的就是解方程

於是乎,我們分類討論即可

\

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstring>
 5 #define ll long long int
 6 using namespace std;
 7 int main()
 8 {
 9     ll n,a,b;
10     ll ans1,ans2;
11     scanf("%lld",&n);
12     if(n==1||n==2)
13     {
14         printf("-1\n");
15         return 0;
16     }
17     else if(n*n%2==1)
18     {
19         ans1=(n*n-1)/2;
20         ans2=(n*n+1)/2;
21     }
22     else
23     {
24         ans1=(n*n/2-2)/2;
25         ans2=(n*n/2+2)/2;
26     }
27     printf("%lld %lld\n",ans1,ans2);
28     return 0;
29 }

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM