G

来源:互联网 发布:剑灵火影捏脸数据 编辑:程序博客网 时间:2024/05/11 21:27

点击打开原题链接

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.

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

Illustration for the first sample.


题目要求很简单,就是让你求出以边n为最短边的直角三角形。由于是让输出随便一组,那我们就可以偷懒了,美滋滋!

解题思路:

(1)因为是直角三角形,所以满足n*n +  m*m = k*k,我们可以转换一下方程n*n = (k-m) * (k+m),因为题目中k大于m,所以我们不必担心此方程的正负号。

(2)设 x =  k - m,  y = k + m;这里我们就转换为求 n*n = x*y,怎样求解x和y呢,因为题目要求随便输出一组,这里我们就可以偷懒了。如果n*n是奇数,那么n*n = 1  *(n*n),这里我们就可以使 x = n*n, y = 1如果n*n 是偶数

那么n*n = 2 * (n * n / 2),这里就让x = n * n / 2, y = 2。

(3)结合步骤(2),我们可以解方程组 x = k - m, y = k + m;我们就可以解出k和m的值了。

上代码:

#include<cstdio>#include<algorithm>using namespace std;int main(){long long n,a,b,x,y;scanf("%lld",&n);if(n%2==1){long long n_n = n*n;x = (n_n + 1 )/2;y = n_n  - x;if(x<=0||y<=0)               {                printf("-1\n");//因为是三角形,它的三条边肯定都是正数        }else{  printf("%lld %lld",y,x);}}else{long long n_n = n*n;        x = (n_n/2 + 2)/2;y = x - 2;if(x<=0||y<=0){printf("-1\n"); //因为是三角形,它的三条边肯定都是正数}else{printf("%lld %lld\n",y,x); } }    return 0;} 

水波。



0 0
原创粉丝点击