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. 3993: [SDOI2015]星际战争

    3993: [SDOI2015]星际战争 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 1244  Solved: ...

  2. 【BZOJ2298】[HAOI2011]problem a DP

    [BZOJ2298][HAOI2011]problem a Description 一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话(可能有相 ...

  3. JavaScript基础深入之

    JS的数值类型是分为两类:基本数据类型和引用数据类型. 基本类型占据的内存栈空间,引用类型被保存在堆空间.引用类型赋值的变量也是被保存在栈空间的,它的作用类似于电视遥控器,负责操作堆空间内指向的对象. ...

  4. 网络免费API接口整理

    转载自: https://www.cnblogs.com/doit8791/p/9351629.html 从网上看到一些免费API接口,在个人开发小程序等应用练手时可试用. 各类无次数限制的免费API ...

  5. Python3.6全栈开发实例[010]

    10.有字符串 "k:1|k1:2|k2:3|k3:4" 处理成字典 {'k':1,'k1':2....} s = "k:1|k1:2|k2:3|k3:4" d ...

  6. hive批量执行sql命令及使用小技巧

    root@hadoop-senior hive-0.13.1]$ bin/hive -helpusage: hive -d, --define <key=value> Variable s ...

  7. Pycharm中SQL语句提示SQL Dialect is Not Configured

    解决办法: 在File---->Setting--->Languages & Frameworks--->SQL Dialects中,选择对应的数据库,如MySQL,之后点击 ...

  8. payload有效载荷(转)

    payload 记载着信息的那部分数据.通常在传输数据时,为了使数据传输更可靠,要把原始数据分批传输,并且在每一批数据的头和尾都加上一定的辅助信息,比如这一批数据量的大小,校验位等,这样就相当于给已经 ...

  9. Android Studio工程引用第三方so文件

    应用程序二进制接口(Application Binary Interface)定义了二进制文件(尤其是.so文件)如何运行在相应的系统平台上,从使用的指令集,内存对齐到可用的系统函数库.在Androi ...

  10. C#多线程基础,适合新手了解

    一.创建线程 在整个系列文章中,我们主要使用Visual Studio 2015作为线程编程的主要工具.在C#语言中创建.使用线程只需要按以下步骤编写即可: 1.启动Visual Studio 201 ...