我可不是为了被全人类喜欢才活着的,只要对于某一个人来说我是必要|

王陸

园龄:6年11个月粉丝:2052关注:178

Pythagorean Triples毕达哥斯拉三角(数学思维+构造)

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 nm 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

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

Hint

Illustration for the first sample.

 

 题目意思:给你一条边,求出另外的两条边,使得这三条边能够构造出一个直角三角形。
 
 解题思路:首先要明确一点,题目说过如果有多个解,只要输出一组就可以了,我认为这个要求很关键,只要构造出一组解就行,实际上这样也解放了思维。比如所给的边,可以是直角边,也可以是斜边,但我们知道如果是直角边那么一定可以找出一组边与其构成直角三角形;但是如果是斜边的话,则不一定能够找出一组边,所以假定所给的边为直角边更好。那么接下来分析:

假设输入的n是一条直角边的长度,那么

\

根据平方差公式可得

\

那么,这个时候,我们要求解的就是a,b

要明确,我们只不过要求解一组解即可!在对n^2划分奇偶后,只要构造出整数解即可!

接下来要做的就是解方程

于是乎,我们分类讨论即可

\

复制代码
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstring>
 5 #define ll long long int
 6 using namespace std;
 7 int main()
 8 {
 9     ll n,a,b;
10     ll ans1,ans2;
11     scanf("%lld",&n);
12     if(n==1||n==2)
13     {
14         printf("-1\n");
15         return 0;
16     }
17     else if(n*n%2==1)
18     {
19         ans1=(n*n-1)/2;
20         ans2=(n*n+1)/2;
21     }
22     else
23     {
24         ans1=(n*n/2-2)/2;
25         ans2=(n*n/2+2)/2;
26     }
27     printf("%lld %lld\n",ans1,ans2);
28     return 0;
29 }
复制代码

 

 

本文作者:王陸

本文链接:https://www.cnblogs.com/wkfvawl/p/9480196.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   王陸  阅读(2526)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起