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
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n;
LL a,b; inline int getint(){
int w=,q=;char c=getchar();
while(c!='-' && (c<'' || c>'')) c=getchar();
if(c=='-') q=-,c=getchar();
while(c>='' && c<='') w=w*+c-'',c=getchar();
return w*q;
} int main()
{
n=getint();
if(n<=) printf("-1");
else if(n&) {
a=n*n-; a/=; b=a+;
printf("%I64d %I64d",a,b);
}
else {
n/=;
a=n*n-; b=n*n+;
printf("%I64d %I64d",a,b);
}
return ;
}

codeforces707C:Pythagorean Triples的更多相关文章

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

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

  2. Pythagorean Triples

    Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Pythagorean Triples 707C

    Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theor ...

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

    C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...

  5. Pythagorean Triples毕达哥斯拉三角(数学思维+构造)

    Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...

  6. codeforces 707C C. Pythagorean Triples(数学)

    题目链接: C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input ...

  7. codeforces-707 C. Pythagorean Triples

    C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. CodeForces 707C Pythagorean Triples (数论)

    题意:给定一个数n,问你其他两边,能够组成直角三角形. 析:这是一个数论题. 如果 n 是奇数,那么那两边就是 (n*n-1)/2 和 (n*n+1)/2. 如果 n 是偶数,那么那两边就是 (n/2 ...

  9. 【数学】Codeforces 707C Pythagorean Triples

    题目链接: http://codeforces.com/problemset/problem/707/C 题目大意: 给你一个数,构造其余两个勾股数.任意一组答案即可,没法构造输出-1. 答案long ...

随机推荐

  1. B - Catch That Cow (抓牛)

    B - Catch That Cow Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  2. c#文件流汇总

    操作文件比较常见,项目中经常出现这样的需求:按每个月自动创建文件,并且向文件里面插入一些数据,那么我们将要分析,文件是否存在的情况:如果存在则直接打开文件流向文件中插入数据,如果不存在,则创建文件再插 ...

  3. inner join和out join的区别

    inner join(又叫join) out join包括left join,right join和full join(也就是left+right)

  4. flex 均分铺满

    <view>充值金额</view> <view class="weui-flex"> <repeat for="{{amount ...

  5. python系列一:python3基础语法

    '''python保留字即关键字,我们不能把它们用作任何标识符名称.Python 的标准库提供了一个 keyword 模块,可以输出当前版本的所有关键字: '''>>> import ...

  6. h5 localStorage本地存储

    用户名:<input type="text" id="txtname"/> 密码:<input type="text" i ...

  7. LATEX教程(二)

    插入图片 \documentclass{article} \usepackage{graphicx} \usepackage{Ctex} \title{插入图片} \author{yif} \begi ...

  8. re模块(Python中的正则表达式)

    re模块 正则表达式本身是一种小型的.高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序媛们可以直接调用来实现正则匹配.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引擎 ...

  9. Kafka配置参数说明

    配置文件目录:/usr/local/kafka/config配置文件server.propertis参数说明:broker.id=0每一个broker在集群中的唯一标识,要求是正数,当该服务器的IP地 ...

  10. PHP获取域名、IP地址的方法

    本文介绍下,在php中,获取域名以及域名对应的IP地址的方法,有需要的朋友参考下. 在php中可以使用内置函数gethostbyname获取域名对应的IP地址,比如: 1 <?php 2 ech ...