Codeforces Round #368 (Div. 2) -- C. Pythagorean Triples (数学公式)

来源:互联网 发布:淘宝模特一天多少衣服 编辑:程序博客网 时间:2024/06/05 18:51
C. Pythagorean Triples
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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 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 thatn, m andk 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.

Examples
Input
3
Output
4 5
Input
6
Output
8 10
Input
1
Output
-1
Input
17
Output
144 145
Input
67
Output
2244 2245
Note

大体题意:
给你一个直角三角形的边n,求出另外两个边的大小(随意输出一个),不存在输出-1!
思路:
没有做出来,当时是瞎暴的,枚举角度 不是超时 就是WA !!
赛后借鉴了大神的代码!
只能当作公式来记了!
直角三角形竟然仅仅没有1 和2 其余的都存在!
如果n能整除4,那就是a/4*3和 a/4*5了!
如果n能整除2  那就是(a/2)*(a/2)/2 * 2,和 ((a/2)*(a/2)/2 +1)* 2
否则对于一般的数那就是a*a/2和 a*a/2+1!

#include<bits/stdc++.h>using namespace std;typedef long long ll;int main(){    ll a;    scanf("%I64d",&a);    if (a == 1 || a == 2){        printf("-1\n");        return 0;    }    if (a % 4 == 0){        printf("%I64d %I64d\n",a/4*3,a/4*5);        return 0;    }    if (a % 2 == 0){        ll t = a/2;        printf("%I64d %I64d\n",(t*t/2)*2, (t*t/2+1)*2 );        return 0;    }    printf("%I64d %I64d\n",a*a/2,a*a/2+1);    return 0;}



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 公司核名通过不想用了怎么办 公司核名下来了不想注册了怎么办 家人受到小贷公司催款威胁怎么办 商标抽签资料提交上去有问题怎么办 花椒直播助手苹果版下载不了怎么办 在香港酒店住把床单弄上血了怎么办 综英美我能怎么办我也很绝望百度云 护照的名字中间有个空格怎么办 开车不小心压死黄鼠狼了怎么办 三户联保贷款一方不还怎么办 因为隔断中介违约…我该怎么办 上海居住证没下来换住址了怎么办 工商注册后大股东不注资怎么办 公司不给去办理变更股东信息怎么办 滴滴车主注册没有自己的车型怎么办 代办用虚假地址注册的公司怎么办? 写字楼注册公司租户不租了怎么办 租户没把公司迁出我该怎么办 租户不肯把户口迁出了业主怎么办 同片区个体户营业场所搬迁怎么办 个体领发票的本丢了怎么办 领房产证发票和合同丢了怎么办 税务登记证5年没有办怎么办 二证合一后税务登记证怎么办? 微信漂流瓶打招呼对方收不到怎么办 添加不上徽信好友的微信帐号怎么办 手机号码不用了微信密码忘了怎么办 别人用我的手机号码注册微信怎么办 电脑此网站的安全证书有问题怎么办 起诉离婚开庭时被告不到场怎么办 商标35类被别人注册了怎么办 商标被注销后被别人注册怎么办 电商35类商标被抢注怎么办 血小板太低怎么办可以吃水果吗? 微信好友删除了只记得昵称怎么办 优酷会员1080p很卡怎么办 电脑最下面的任务栏不显示怎么办 ea账号保留的问题忘了怎么办 微博超级话题账号被屏蔽怎么办 梦幻西游手机将军令号码换了怎么办 文档的内容被锁定无法修改怎么办