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划分奇偶后,只要构造出整数解即可!

接下来要做的就是解方程

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

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define ll long long int
using namespace std;
int main()
{
ll n,a,b;
ll ans1,ans2;
scanf("%lld",&n);
if(n==||n==)
{
printf("-1\n");
return ;
}
else if(n*n%==)
{
ans1=(n*n-)/;
ans2=(n*n+)/;
}
else
{
ans1=(n*n/-)/;
ans2=(n*n/+)/;
}
printf("%lld %lld\n",ans1,ans2);
return ;
}
 

Pythagorean Triples毕达哥斯拉三角(数学思维+构造)的更多相关文章

  1. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

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

    C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...

  3. codeforces 707C C. Pythagorean Triples(数学)

    题目链接: C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input ...

  4. codeforces-707 C. Pythagorean Triples

    C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  6. codeforces707C:Pythagorean Triples

    Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...

  7. Pythagorean Triples

    Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. 程序设计中的数学思维函数总结(代码以C#为例)

    最近以C#为例,学习了程序设计基础,其中涉及到一些数学思维,我们可以巧妙的将这些逻辑问题转换为代码,交给计算机运算. 现将经常会使用到的基础函数做一总结,供大家分享.自己备用. 1.判断一个数是否为奇 ...

  9. Pythagorean Triples 707C

    Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theor ...

随机推荐

  1. OO第三次博客作业——规格

    OO第三次博客作业——规格 一.调研结果: 规格的历史: 引自博文链接:http://blog.sina.com.cn/s/blog_473d5bba010001x9.html 传统科学的特点是发现世 ...

  2. summernote富文本编辑器的使用

    最近在开发一个微信公众号的后台,微信公众号编辑的文章一直没有得到很好地适应,大多数人也是在其他的编辑软件中编辑好之后直接去复制到微信公众平台中,考虑到复制后会排版出现问题,所以给大家推荐一款很不错的W ...

  3. IE浏览器中找不到开发者工具

    ie浏览器不知道什么原因开发者工具不见了.打开以后在任务栏中显示打开了控制台,但是看不到. 解决方法 : F12 打开开发者工具后,按下 “ Ctrl + P ”

  4. Linux基础入门---学习心得

    之前一直以为Linux和Windows差不多,但是学习了Linux基础入门之后才发现两种操作系统之间差距非常大. Linux只是在硬件之上的内核和系统调用,就连我们在Windows里习以为常的图形界面 ...

  5. 网站漏洞修复案例之Discuz!3.4最新版本

    Discuz!论坛目前最新版本为3.4版本,已经好久没有更新了,我们SINE安全在对其网站安全检测的同时发现一处漏洞,该漏洞可导致论坛的后台文件可以任意的删除,导致网站瘫痪,后台无法登陆.关于该网站漏 ...

  6. SQL注入科普

    技术交流,安全交友联系渔夫”小白“,微信号(xz116035) SQL注入介绍 SQL注入攻击是最为常见的Web应用安全漏洞之一,国外知名安全组织OWASP针对web应用安全漏洞进行了一个排名,SQL ...

  7. Asp.Ner Core定时任务

    AspNet Core定时任务 纪念人类首张黑洞照片发布 第一种方式BackgroundService 基于后台服务类BackgroundService实现,类所在命名空间Microsoft.Exte ...

  8. sed: unix与doc换行的转换

    在Linux (Unix)平台下回车换行以\n表示 在Window平台下回车换行以\r\n表示 两者的差异导致了: 在window下看Linux的文本排版全乱 在Linux在看Window的文本则是存 ...

  9. Spring Cloud学习入门路线方案

    Spring Cloud 为开发者提供了在分布式系统(如配置管理.服务发现.断路器.智能路由.微代理.控制总线.一次性Token.全局锁.决策竞选.分布式会话和集群状态)操作的开发工具.本Spring ...

  10. 关于快速沃尔什变换(FWT)的一些个人理解

    定义 FWT是一种快速完成集合卷积运算的算法. 它可以用于求解类似 $C[i]=\sum\limits_{j⊗k=i}A[j]*B[k]$ 的问题. 其中⊗代表位运算中的|,&,^的其中一种. ...