Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学
C. Pythagorean Triples
题目连接:
http://www.codeforces.com/contest/707/problem/C
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 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 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.
Sample Input
3
Sample Output
4 5
Hint
题意
给你直角三角形的一边长度,让你找到两个整数,是其他两条边的边长,问你能否找到。
题解:
其实是公式题,随便百度了一下,就找到结论了= =
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
if(n<=2){
cout<<"-1"<<endl;
return 0;
}
if(n%2)
{
long long a=(n-1LL)/2LL;
cout<<2LL*a*a+2LL*a<<" "<<2LL*a*a+2LL*a+1LL<<endl;
return 0;
}
else
{
long long a=n/2;
cout<<a*a-1<<" "<<a*a+1<<endl;
}
}
Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学的更多相关文章
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- 暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II
题目传送门 /* 暴力:O (n^2) */ #include <cstdio> #include <algorithm> #include <cstring> # ...
- Codeforces Round #368 (Div. 2) C
Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...
- Codeforces Round #368 (Div. 2)A B C 水 图 数学
A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #368 (Div. 2) A , B , C
A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Pythagorean Triples(Codeforces Round #368 (Div. 2) + 构建直角三角形)
题目链接: https://codeforces.com/contest/707/problem/C 题目: 题意: 告诉你直角三角形的一条边,要你输出另外两条边. 思路: 我们容易发现除2外的所有素 ...
随机推荐
- bzoj千题计划259:bzoj3122: [Sdoi2013]随机数生成器
http://www.lydsy.com/JudgeOnline/problem.php?id=3122 等比数列求和公式+BSGS #include<map> #include<c ...
- bzoj千题计划192:bzoj1569: [JSOI2008]Blue Mary的职员分配
http://www.lydsy.com/JudgeOnline/problem.php?id=1569 dp[i][j][a][b] 表示i个职员,发广告状态为j,已有金钱a,声誉b的最少天数 j= ...
- Web性能优化系列(3):如何延迟加载JS
本文由 伯乐在线 - J.c 翻译,sunbiaobiao 校稿.未经许可,禁止转载!英文出处:www.feedthebot.com.欢迎加入翻译小组. 延迟加载JavaScript JavaScri ...
- angularJs入门篇-hello world 开头
AngularJS 采用了完全不同的解决方案,它创建实时视图模板代替视图,而不是将数据合并进模板之后更新DOM. 任何一个独立视图组件中的值都是 动态替换的.这个功能可以说是AngularJS中最重要 ...
- 第8月第15天 app支持后台播放
1. AVAudioSession *audioSession = [AVAudioSession sharedInstance]; //默认情况下扬声器播放 [audioSession setCat ...
- MySQL-存储过程procedure
存储过程:是一个SQL语句集合,当主动去调用存储过程时,其中内部的SQL语句会按照逻辑执行. 1.创建存储过程: -- 创建存储过程 delimiter // create procedure p1( ...
- CSS position:absolute浅析
一.绝对定位的特征 绝对定位有着与浮动一样的特性,即包裹性和破坏性. 就破坏性而言,浮动仅仅破坏了元素的高度,保留了元素的宽度:而绝对定位的元素高度和宽度都没有了. 请看下面代码: <!DOCT ...
- mongodb导出数据csv格式
mongoexport -d test -c item --type=csv -f salary,city,workYear,companyShortName -o user.csvmongoexpo ...
- 微信小程序调用接口返回数据或提交数据
由于小程序发起网络请求需要通过 wx.request 文档地址 https://mp.weixin.qq.com/debug/wxadoc/dev/api/network-request.html 习 ...
- springcloud使用Hystrix实现微服务的容错处理
使用Hystrix实现微服务的容错处理 容错机制 如果服务提供者相应非常缓慢,那么消费者对提供者的请求就会被强制等待,知道提供者相应超时.在高负载场景下,如果不作任何处理,此类问题可能会导致服务消费者 ...