codeforces707C: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 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 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.

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

正解:数学(数论)解题报告:  n<=2显然无解。  若n为奇数,则另两个为(a*a-1)/2和(a*a+1)/2;  若n为偶数,则另两个为(a/2)*(a/2)-1和(a/2)*(a/2)+1
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<algorithm>
 7 using namespace std;
 8 typedef long long LL;
 9 LL n;
10 LL a,b;
11
12 inline int getint(){
13     int w=0,q=1;char c=getchar();
14     while(c!=‘-‘ && (c<‘0‘ || c>‘9‘)) c=getchar();
15     if(c==‘-‘) q=-1,c=getchar();
16     while(c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘,c=getchar();
17     return w*q;
18 }
19
20 int main()
21 {
22     n=getint();
23     if(n<=2) printf("-1");
24     else if(n&1) {
25     a=n*n-1; a/=2; b=a+1;
26     printf("%I64d %I64d",a,b);
27     }
28     else {
29     n/=2;
30     a=n*n-1; b=n*n+1;
31     printf("%I64d %I64d",a,b);
32     }
33     return 0;
34 }
时间: 2024-12-20 17:12:36

codeforces707C:Pythagorean Triples的相关文章

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

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 707C Pythagorean Triples (数论)

题意:给定一个数n,问你其他两边,能够组成直角三角形. 析:这是一个数论题. 如果 n 是奇数,那么那两边就是 (n*n-1)/2 和 (n*n+1)/2. 如果 n 是偶数,那么那两边就是 (n/2*n/2-1) 和 (n/2*n/2+1).那么剩下的就很简单了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #

Pythagorean Triples CodeForces - 707C 推理题,大水题

给定一个数n(1 <= n <= 1e9),判断这个数是否是一个直角三角形的边长,如果是,则输出另外两条边(1 <= x <= 1e18),否则输出-1. 参考题解:http://blog.csdn.net/harlow_cheng/article/details/69055614 首先,当n <= 2 的时候无解,其他时候都有解 假设n是直角边,a是斜边,则n^2 + b^2 = a^2; n^2 = (a + b)*(a - b); ①假设n是偶数,则另(a - b) =

Codeforces 707C. Pythagorean Triples

题目链接:http://codeforces.com/problemset/problem/707/C 题意: 给你直角三角形其中一条边的长度,让你输出另外两条边的长度. 思路: 直接构造勾股数即可,构造勾股数的方法: 当 a 为大于 1 的奇数 2 * n+1 时, b = 2 * n * n + 2 * n, c = 2 * n * n + 2 * n + 1. 当 a 为大于 4 的偶数 2 * n 时,b = n * n - 1, c = n * n + 1. 然后不满足上述构造方法的数

【数学】Codeforces 707C Pythagorean Triples

题目链接: http://codeforces.com/problemset/problem/707/C 题目大意: 给你一个数,构造其余两个勾股数.任意一组答案即可,没法构造输出-1. 答案long long 范围. 题目思路: [数学] 这里贴一下勾股数的构造: 当a为大于1的奇数2n+1时,b=2n2+2n, c=2n2+2n+1. 实际上就是把a的平方数拆成两个连续自然数,例如: n=1时(a,b,c)=(3,4,5) n=2时(a,b,c)=(5,12,13) n=3时(a,b,c)=

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 707C】Pythagorean Triples(找规律)

一边长为a的直角三角形,a^2=c^2-b^2.可以发现1.4.9.16.25依次差3.5.7.9...,所以任何一条长度为奇数的边a,a^2还是奇数,那么c=a^2/2,b=c+1.我们还可以发现,1.4.9.16.25.36各项差为8.12.16.20,偶数的平方是4的倍数,那么c=a^2/4-1,b=a^2/4+1. #include <iostream> using namespace std; int main() { long long n; cin>>n; n*=n;

勾股数组【学习笔记】

本原勾股数组(简写为PPT)是一个三元组(a,b,c),其中a,b,c没有公因数,且满足.例如下面是一项本原勾股数组: (3,4, 5),(5,12,13),(8,15,17),(7,24,25),(9,40,41),(11,60,61),(28,45,56),(33,56,65). 由这个短表容易得到一些结论,例如,似乎a与b奇偶性不同且c总是奇数. 证明如下: 若a与b都是偶数,则c也是偶数,意味着a,b,c有公因数2,所以三元组不是本原的,其次,若a,b都是奇数,那么c必然是偶数,这样假设