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 ...
随机推荐
- Selector空轮询处理(转载)
https://www.cnblogs.com/my_life/articles/5556939.html Selector空轮询处理 在NIO中通过Selector的轮询当前是否有IO事件,根据JD ...
- Jmeter(二十)Beanshell or JSR223
有关Beanshell和JSR223组件的部分,早就想写一大篇幅随笔进行记录,苦于不知如何去描述这两部分的内容,一直在修改随笔. 介绍一下Beanshell: Beanshell是轻量级Java,支持 ...
- Anaconda(python3.6)中使用python2.7
因为我现在安装的是最新版Anaconda3,其自带的Python版本为3.6,如果我们需要添加2.7版本的Python,可以进行如下操作.(同理,如果有人安装的是Anaconda2需要添加Python ...
- Http跨域
一.传统 ajax跨域访问是一个老问题了,解决方法很多,比较常用的是JSONP方法,JSONP方法是一种非官方方法,而且这种方法只支持GET方式,不如POST方式安全. 即使使用jQuery的json ...
- HADOOP+SPARK+ZOOKEEPER+HBASE+HIVE集群搭建(转)
原文地址:https://www.cnblogs.com/hanzhi/articles/8794984.html 目录 引言 目录 一环境选择 1集群机器安装图 2配置说明 3下载地址 二集群的相关 ...
- 10 sed命令的基本用法
grep灵活的关联正则表达式实现文件过滤,而sed是一个数据流的编辑器,或者说是一个行编辑器,它将文件一行一行的数据放入到内存中进行编辑,而awk是一个报告生成器,这个我们以后再说: 之前我们介绍过g ...
- AS导入项目报错:Plugin with id 'com.android.application' not found.
从github或第三方Demo中获取的项目导入到AndroidStudio中报错Plugin with id 'com.android.application' not found.:今天导入一个讯飞 ...
- Vue-ui常用组件库整理
Vue-ui常用组件库整理 查看全部整理内容==> element-ui Element 是由饿了么UED设计.饿了么大前端开发的一套基于 Vue 2.0 的桌面端组件库. 这款是我用了很久的, ...
- python学习笔记目录
人生苦短,我学python学习笔记目录: week1 python入门week2 python基础week3 python进阶week4 python模块week5 python高阶week6 数据结 ...
- C# WPF DevExpress 图表控件之柱状图
说明:DevExpress版本是17.1.VS是2015. XAML: <!--#region 图表控件--> <dxc:ChartControl x:Name="char ...