Pythagorean Triples 707C
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?
The only line of the input contains single integer n (1 ≤ n ≤ 109) — the length of some side of a right triangle.
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.
3
4 5
6
8 10
1
-1
17
144 145
67
2244 2245
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;
#include<cstdio>
int main()
{
long long n;
while(~scanf("%lld",&n))
{
long long b,c;
if(n%!=)//当直角边时奇数的时候直接执行
{
b=(n*n-)/;
c=b+;
if(b==)
printf("-1\n");
else
printf("%lld %lld\n",b,c);
}
else//当直角边是偶数的时候
{
long long t=;
while()
{
if(n==)
break;
if(n%!=)
break;
n/=;
t*=; }//不断除2,看其是否为奇数,或者不断除2等于4
if(n==)
{
b=;
c=;
b*=t;
c*=t;
}//如果等于4就满足,a=,b=,a=5的情况
else
{
b=(n*n-)/;
c=b+;
b*=t;
c*=t;
}//否则就满足a是奇数的情况
if(b==)
printf("-1\n");
else
printf("%lld %lld\n",b,c);
}
}
return ;
}
Pythagorean Triples 707C的更多相关文章
- codeforces 707C C. Pythagorean Triples(数学)
题目链接: C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Pythagorean Triples
Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces-707 C. Pythagorean Triples
C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学
C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...
- Pythagorean Triples毕达哥斯拉三角(数学思维+构造)
Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...
- codeforces707C:Pythagorean Triples
Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...
- 【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.我们还可以发现, ...
- CodeForces 707C Pythagorean Triples (数论)
题意:给定一个数n,问你其他两边,能够组成直角三角形. 析:这是一个数论题. 如果 n 是奇数,那么那两边就是 (n*n-1)/2 和 (n*n+1)/2. 如果 n 是偶数,那么那两边就是 (n/2 ...
随机推荐
- URL优化的几个处理方法
原文链接:http://www.51chinashop.com/shopinfo/dsjs/2014-11-23/100.html 在一个网站中,一个页面对应了多个URL,必然会分散这个页面的权重.因 ...
- 面向对象php 接口 抽象类
1.定义类和实例化对象: 使用关键字class定义类,使用new实例化对象: 2.类成员的添加和访问: 类成员:有属性,方法,常量(常量名不带$符): 访问属性的时候,变量名不带$符 添加属性需要使用 ...
- mysql 5.6 binlog组提交实现原理(转载)
http://blog.itpub.net/15480802/viewspace-1411356/ Redo组提交 Redo提交流程大致如下 lock log->mutex write redo ...
- JavaScript中的类(class)、构造函数(constructor)、原型(prototype)
类 Class 类的概念应该是面向对象语言的一个特色,但是JavaScript并不像Java,C++等高级语言那样拥有正式的类,而是多数通过构造器以及原型方式来仿造实现.在讨论构造器和原型方法前,我可 ...
- 第5章 IP地址和子网划分(1)_IP格式和子网掩码
1. 二进制和十进制 (1)二进制与十进制的对应关系 ①128为数轴的中点,最高位为1.其后的数,二进制最高位均为1.其前面的数二进制最高位均为0. ②192为128-255中间的数,最高两位为1.2 ...
- 不曾忘记的Vue.js
马上2017年就结束了,虽然我因为目前的项目用不上你vue,但是我不曾忘记你,在时间缝隙的某一刹那,我再次将你拾起. vue.js全家桶:vue+ vuex+axios+vue-router+webp ...
- 10进制与16进制之间的转换 delphi
delphi中有直接把10进制转换成16进制的函数: function IntToHex(Value: Integer; Digits: Integer): string; o ...
- Enterprise Library
https://msdn.microsoft.com/en-us/library/ff648951.aspx
- uva-565-枚举
16个披萨配料,选出一种组合满足所有人的需求,当然,如果某个人不喜欢A,结果里不包含A也是满足这个人的.只要答案满足题意既可,答案不唯一,special judge 用位枚举 #include < ...
- ClientAbortException: java.net.SocketException: 断开的管道
这次终于解决了 ClientAbortException ! [ERROR] [- ::] net.jweb.actions.CommonDiskAction - 系统异常 ClientAbortEx ...