Codeforces Round #368 (Div. 2) C. Pythagorean Triples
来源:互联网 发布:双十一淘宝描述不符 编辑:程序博客网 时间:2024/06/05 17:14
C. Pythagorean Triples
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
给你直角三角形的其中一条边问另外两边。
a^2+b^2=c^2 显然有a=s*v;b=(s^2-v^2)/2;c=(s^2+v^2)/2;
所以分奇偶讨论:当n为奇数时显然a=1*n;b=(n^2-1)/2;c=(n^2+1)/2;
n为偶数时,要分成n=2^k或n=2^k*m 对于前者显然有一组已知解 4 3 5
所以只需要构造3*2^(k-2)与5*2^(k-2),对于后者可转化为奇数的情况。
最后要特判n=1与n=2的情况。
#include<stdio.h>#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<math.h>using namespace std;#define F(x,a,b) for (int x=a;x<=b;x++)#define ll long longint main(){ ll n;ll a,b; scanf("%I64d",&n); if (n==1||n==2){printf("-1"); return 0;} if (n&1){a=(n*n+1)/2;b=(n*n-1)/2;printf("%I64d %I64d",a,b);}else { ll t=1,p=n; while (!(p&1)){t=t<<1;p=p>>1;} if (p!=1) {a=(p*p+1)/2*t;b=(p*p-1)/2*t;printf("%I64d %I64d",a,b);return 0;} cout<<3*(t>>2)<<" "<<5*(t>>2); }}
- 【Codeforces Round #368 (Div. 2)】Codeforces 707C Pythagorean Triples
- Codeforces Round #368 (Div. 2) Pythagorean Triples
- Codeforces Round #368 (Div. 2) Pythagorean Triples
- Codeforces Round #368 (Div. 2) -- C. Pythagorean Triples (数学公式)
- Codeforces Round #368 (Div. 2)C Pythagorean Triples
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples (本原勾股数)
- Codeforces Round #368 (Div. 2)-C. Pythagorean Triples
- Codeforces Round #368 (Div. 2)C. Pythagorean Triples
- Codeforces Round #368 (Div. 2) -C. Pythagorean Triples
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples
- Codeforces Round #368 (Div. 2) problem: (C) Pythagorean Triples
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples
- Codeforces 707 C. Pythagorean Triples(找规律)——Codeforces Round #368 (Div. 2)
- Codeforces Round #368-C - Pythagorean Triples-数学
- Codeforces Round #368 C Pythagorean Triples
- Codeforces Round #368 (Div. 2)(C. Pythagorean Triples 勾股数规律)
- Codeforces Round #368 (Div. 2)C.Pythagorean Triples 本原勾股数组
- Android自定义控件:动画类(八)----ObjectAnimator基本使用
- SICP 1.14-1.15
- HashMap和HashSet的区别
- STS配置Maven环境
- C++ string(八)
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples
- JAVA自动化测试之页面对象模型(Page Object)
- Retrofit 分析 - 经典设计模式案例
- 抓屏操作GrabPass
- Android NDK 初探
- 对于一个有序的数组,如果要插入一个元素并保证数组还有序, 问如何获取该元素位置。用二分法
- (c#)AutoCAD二次开发,运行时,出现“对象的当前状态使该操作无效”
- 42. Trapping Rain Water
- CATransform3D参数的意义