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 ...
随机推荐
- switch语句的功能是否完全可以使用if else多选择结构来代替?如果是,为什么还需要switch结构?
- [UE4]游戏主循环
游戏的运行模型 理解游戏的运行模型,对处理很多游戏错误有非常大的帮助. 游戏是有一个主循环的.那么游戏主循环做了什么事情呢? 游戏主循环一次就表示一帧,游戏主循环包括:接受输入.处理游戏逻辑.渲染.S ...
- SCCM2012 R2实战系列之十二:解决OSD分发时间过长的问题
对于SCCM 2012 R2的初学者来说,能够成功分发操作系统可能已经是非常兴奋了.但在企业中会遇到客户提出的各种各样苛刻的需求.所以在平时实验过程中多站点客户的角度想问题,尽可能的贴近企业实际生产环 ...
- Kafka参数详解
一.相关参数配置 System 系统参数 #唯一标识在集群中的ID,要求是正数. broker.id=0 #服务端口,默认9092 port=9092 #监听地址,不设为所有地址 host.name= ...
- Hook技术之API拦截(API Hook)
一.实现过程 1.钩子实际上是一个处理消息的程序段,通过系统调用,把它挂入系统. 2.在消息没有到达目的窗口前,钩子就捕获消息(即钩子函数先得到控制权). 3.钩子可以加工处理该消息,即钩子机制允许应 ...
- restframwork框架
一 APIView: class PublishView(APIView): def get(self,request): publish_list=Publish.objects.all() ret ...
- vue 整合element-ui
本文主要介绍如何在vue框架中结合elementUI. 本文主要参考: http://element-cn.eleme.io/#/zh-CN/component/quickstart 1.阅读本文 ...
- 用Excel建模进行决策树分析
决策树(Decision Tree)在机器学习中也是比较常见的一种算法,最早的决策树算法是ID3,改善后得到了C4.5算法,进一步改进后形成了我们现在使用的C5.0算法,综合性能大幅提高. 算法核心: ...
- ROS进阶学习笔记(11)- Turtlebot Navigation and SLAM
(写在前面: 这里参考rbx书中第八章和ROS社区教程进行学习,先看社区教程) === Doing the Turtlebot Navigation === ref ros wiki: http ...
- Implement a deployment tool such as Ansible, Chef, Puppet, or Salt to automate deployment and management of the production environment
Implement a deployment tool such as Ansible, Chef, Puppet, or Salt to automate deployment and manage ...