Codeforces Round #368 (Div. 2) Pythagorean Triples

Pythagorean Triples

  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 n, m 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.

Examples

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.

题意:  给出一条直角边,求另外的两条边(都为整数)思路:  公式推导题:    这要利用平方差公式    令斜边为c,直角边为a、b    c²-a²=(c+a)(c-a)    因此(c+a)(c-a)是完全平方数,且(c-a)是(c+a)的一个因数    1、如果(c-a)=1,则(c+a)是完全平方数(最短边是任意大于2的奇数)    例如:5、4、3;13、12、5;25、24、7;41、40、9;...    2、如果(c-a)=2,则(c+a)/2是完全平方数(最短边是任意大于2的偶数)    例如:5、3、4;10、8、6;17、15、8;26、24、10;...    即:最短边是任意一个大于2的正整数,都可以配成一个三边都是整数的直角三角形.AC代码

 1 # include <iostream>
 2 using namespace std;
 3 typedef long long int ll;
 4 int main()
 5 {
 6     ll n;
 7     while(cin >> n)
 8     {
 9         if(n <= 2)
10             cout << "-1" << endl;
11
12         else if(n % 2 == 1)
13         {
14             ll a = (n * n + 1) / 2;
15             ll c = (n * n - 1) / 2;
16             cout << c << " " << a << endl;
17         }
18         else
19         {
20             ll a = (n * n) / 4 + 1;
21             ll c = (n * n) / 4 - 1;
22             cout << c << " " << a << endl;
23         }
24     }
25     return 0;
26 }

				
时间: 2024-10-11 04:10:14

Codeforces Round #368 (Div. 2) Pythagorean Triples的相关文章

Codeforces Round #368 (Div. 2) Brain&#39;s Photos

Brain's Photos Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos

Codeforces 707 C. Pythagorean Triples(找规律)——Codeforces Round #368 (Div. 2)

传送门 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 t

Codeforces Round #368 (Div. 2)

A. Brain's Photos 题意: 给你一个n*m的字符矩阵,如果字符中出现'C', 'M', 'Y'这三个中的任何一个就输出"#Color";否则输出"#Black&White". 代码如下: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <fstream> 5 #include <ctime&

Codeforces Round #368 (Div. 2) ABCD

A. Brain's Photos 题解: 水得不要不要的 代码: #include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define LL long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)

Codeforces Round #368 (Div. 2) C

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 corresp

Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

给定一个直角三角形的一边长度.问是否存在一个直角三角形,使得它满足有一边的长度是x 当x=1.2的时候是无解的,可以暴力打表看看. 注意到,相邻的两个数的平方的差值是奇数 x^2 - (x-1)^2 = 2*x-1 间隔为2的两个数的平方的差值是偶数 (x+1)^2 - (x-1)^2 = 4*x 这样就可以分类讨论了. 把n永远当成是指角边就OK #include <cstdio> #include <cstdlib> #include <cstring> #incl

Codeforces Round #368 (Div. 2) Bakery

Bakery Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply

Codeforces Round #368 (Div. 2) A

Description Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are

Codeforces Round #368 (Div. 2) B

Description Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour su