您的位置:首页 > 编程语言 > Go语言

[codeforces] C - Pythagorean Triples 数学

2016-10-13 21:58 190 查看
C - Pythagorean Triples
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
707C

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 calledPythagorean 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.

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.

对于直角三角形△ABC,如图:



我们知道的是



因为题目说如果题目存在多种解,输出任何一个就可以了,所以我们不妨假设输入的n是一条直角边的长度,那么



根据平方差公式可得



那么,这个时候,我们要求解的就是a,b

于是乎,我们分类讨论即可



#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 10007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1#define Rson mid+1, R, rt<<1|1const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

int main()
{
ll n;
scanf("%I64d",&n);
if(n==1||n==2)
puts("-1");
else if(n*n%2)
printf("%I64d %I64d\n",(n*n-1)/2,(n*n+1)/2);
else
printf("%I64d %I64d\n",(n*n/2-2)/2,(n*n/2+2)/2);
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: