博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Pythagorean Triples 707C
阅读量:5126 次
发布时间:2019-06-13

本文共 2655 字,大约阅读时间需要 8 分钟。

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 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
Copy
3
output
Copy
4 5
input
Copy
6
output
Copy
8 10
input
Copy
1
output
Copy
-1
input
Copy
17
output
Copy
144 145
input
Copy
67
output
Copy
2244 2245
Note

Illustration for the first sample.

 

 题意:给你一条直角边,让你求出另一条直角边与斜边,如果没有,则输出-1

分析:a²+b²=c²,a²=(c-b)(c+b),如果a是奇数,c-b=1,c+b=a*a,c=a*a+1/2, b=c-1.如果a是偶数,先判断,1:如果不断的除2,是否是奇数,是奇数就执行c=a*a+1/2, b=c-1;2:当其不断除2等于4时,执行c=5,b=3;

1 #include
2 int main() 3 { 4 long long n; 5 while(~scanf("%lld",&n)) 6 { 7 long long b,c; 8 if(n%2!=0)//当直角边时奇数的时候直接执行 9 {10 b=(n*n-1)/2;11 c=b+1;12 if(b==0)13 printf("-1\n");14 else15 printf("%lld %lld\n",b,c);16 }17 else//当直角边是偶数的时候18 {19 long long t=1;20 while(1)21 {22 if(n==4)23 break;24 if(n%2!=0)25 break;26 n/=2;27 t*=2;28 29 }//不断除2,看其是否为奇数,或者不断除2等于430 if(n==4)31 {32 b=3;33 c=5;34 b*=t;35 c*=t;36 }//如果等于4就满足,a=4,b=3,a=5的情况37 else38 {39 b=(n*n-1)/2;40 c=b+1;41 b*=t;42 c*=t;43 }//否则就满足a是奇数的情况44 if(b==0)45 printf("-1\n");46 else47 printf("%lld %lld\n",b,c);48 }49 }50 return 0;51 }

 

转载于:https://www.cnblogs.com/LLLAIH/p/9700019.html

你可能感兴趣的文章
C#委托的介绍(delegate、Action、Func、predicate)
查看>>
hbase rest api接口链接管理【golang语言版】
查看>>
IOS的七种手势
查看>>
hadoop中map和reduce的数量设置问题
查看>>
剑指offer
查看>>
Mdi悬浮子窗体不超过主窗体边界
查看>>
再论递归
查看>>
[给ASP.NET 初学者的话]不要练功练了三年,才发现自己必须「砍掉重练」!....学习ASP.NET之前,请先把自己杯中的水倒掉...
查看>>
集合框架(一) ----------Map集合遍历的方法
查看>>
2015.5.21 Core Java Volume 1
查看>>
InnoDB还是MyISAM?
查看>>
struts2拦截器详解
查看>>
Mysql常用语句
查看>>
.Net学习笔记----2015-06-30(超市收银系统01-仓库类)
查看>>
累觉不爱
查看>>
Flyweight Design Pattern 共享元设计模式
查看>>
ftp的本地用户搭建
查看>>
Flume环境搭建_五种案例(转)
查看>>
uva11991 Easy Problem from Rujia Liu?
查看>>
你理解我的意思么?
查看>>