Pythagorean Triples
1 second
256 megabytes
standard input
standard output
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 calledPythagorean 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.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t;
int main()
{
int i,j;
ll p;
scanf("%lld",&p);
p=p*p;
if(p&)
{
ll ans1=(p-)/,ans2=ans1+;
if(ans1)printf("%lld %lld\n",ans1,ans2);
else puts("-1");
}
else
{
p/=;
if(p&)puts("-1");
else
{
ll ans1=(p-)/,ans2=ans1+;
if(ans1)printf("%lld %lld\n",ans1,ans2);
else puts("-1");
}
}
//system("Pause");
return ;
}
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-707 C. Pythagorean Triples
C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Pythagorean Triples 707C
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theor ...
- 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 C. Pythagorean Triples(数学)
题目链接: C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input ...
- 【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 ...
随机推荐
- node.js作为“简单HTTP服务器”
场景 当我学习一个JavaScript库的时候,需要一个非常简单的HTTP服务器把当前工作路径变为网站根目录,由此来访问网页的静态信息.现在,除了下边的脚本server.js,假设你已经拥有: 一个工 ...
- SpringMVC redirect乱码问题
转:http://blog.csdn.net/xubo_zhang/article/details/8239725 spring redirect 用spring redirect中文会乱码:如下示例 ...
- 转 EXPDP ORA-39095 ORA-3909 错误
今天帮同事在测试库上导出两张表,第一张表大小为30M,第二章表大小为7G,以下是expdp语法 expdp tranuser/******** parallel=4 content=data_only ...
- HTML+CSS Day06 超链接的样式与搭配
1.格式 a:link {} 普通的.未被访问的链接 a:visited {} 用户已访问的链接 a:hover {} 鼠标指针位于链接的上方 a:active{} 链接被点击的时刻 2.常 ...
- 关于js向jsp中传输中文乱码问题
最近做项目遇到的js向jsp中传中文结果是乱码,不知道是否是我换了用eclipse的原因还是什么,以前用的MyEclipse反正最后解决办法如下: 1.把js文件复制到桌面: 2.打开文件并用另存为u ...
- 用for while 成绩的有效输入
#include "stdio.h" void main() { int score,s; printf("请输入你的成绩:"); scanf("%d ...
- HDU 3038 How Many Answers Are Wrong (并查集)---并查集看不出来系列-1
Problem Description TT and FF are ... friends. Uh... very very good friends -________-bFF is a bad b ...
- HDU 2609 How many
最小表示法+Map或者字典树,最小表示法找了个模板,还没学习呢... #include<cstdio> #include<cstring> #include<cmath& ...
- HDU1372,BFS象棋马走日
简单的对于bfs的运用,但是还是写的太慢了写了TMD的1H,主要是不熟悉,以后慢慢熟悉就好了,模型基本已经能建立了,主要出现bug是在方向数组的运用上面,一定要记得是从0开始的,而不是从1开始的,导致 ...
- int *p[4]与int (*q)[4]的区别
以上定义涉及两个运算符:“*”(间接引用).“[]”(下标),“[]”的优先级别大于“*”的优先级别. 首先看int *p[4],“[]”的优先级别高,所以它首先是个大小为4的数组,即p[4]:剩下的 ...