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 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
4 5
6
8 10
1
-1
17
144 145
67
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毕达哥斯拉三角(数学思维+构造)的更多相关文章
- 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) C. Pythagorean Triples 数学
C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...
- codeforces 707C C. Pythagorean Triples(数学)
题目链接: C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input ...
- codeforces-707 C. Pythagorean Triples
C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standa ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- codeforces707C:Pythagorean Triples
Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...
- Pythagorean Triples
Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 程序设计中的数学思维函数总结(代码以C#为例)
最近以C#为例,学习了程序设计基础,其中涉及到一些数学思维,我们可以巧妙的将这些逻辑问题转换为代码,交给计算机运算. 现将经常会使用到的基础函数做一总结,供大家分享.自己备用. 1.判断一个数是否为奇 ...
- Pythagorean Triples 707C
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theor ...
随机推荐
- 关于js中的原型
- 关于TCP传输的三次握手四次挥手策略
简单小总结: 一般为了能够准确无误地把数据送达目标处,TCP协议采用了三次握手策略.用TCP协议把数据包送出去后,TCP不会对传送后的情况置之不理,它一定会向对方确认是否成功送达. 注:握手过程中使用 ...
- 话说文件系统——aufs源码分析(三)
1. linux中设备驱动的入口都是:module_init(xxx_init);里面注册的函数,对于文件系统来说也是一样的,对于aufs来说,就是aufs_init,具体如下 //用于描述aufs文 ...
- 利用wireshark抓取TCP的整个过程分析。
原文地址:https://www.cnblogs.com/NickQ/p/9226579.html 最近,已经很久都没有更新博客了.看看时间,想想自己做了哪些事情,突然发现自己真的是太贪心,到头来却一 ...
- 文件句柄W模式
f1=open('lo',encoding='utf-8',mode='w')f1.write('w4567')print(f1.tell())f1.close() #tell 告诉指针的位置(按字节 ...
- PTA(BasicLevel)-1006换个格式输出整数
一 换格式输出整数 用字母 B 来表示“百”.字母 S 表示“十”,用 12...n 来表示不为零的个位数字 n(<10),换个格式来输出任一个不超过 3 位的正整数.例如 234 应该被 ...
- 20155211实验二 Java面向对象程序设计
20155211实验二 Java面向对象程序设计 实验内容 1.初步掌握单元测试和TDD 2.理解并掌握面向对象三要素:封装.继承.多态 3.初步掌握UML建模 4.熟悉S.O.L.I.D原则 5.了 ...
- 预备作业03:虚拟机安装及Linux操作系统练习
安装虚拟机 安装时遇到的问题 在打开虚拟机时出现以下问题: 经查询该问题只需要更改其兼容性,使其"以管理员身份运行". 常用的Linux命令 $ who am i:查看当前伪终端的 ...
- 20155316 2016-2017-2《Java程序设计》课程总结
每周作业 链接汇总 预备作业1:学习调查(专业期望 师生关系 代码行数) 预备作业2:"做中学"调查(日常技能 C语言 Java 公文写作) 预备作业3:Linux系统与虚拟机学习 ...
- c++ 创建单项链表
建立单向链表 头指针Head 插入结点 //建立头结点 Head Head=p= malloc(sizeof( struct stu_data)); // memset(stu,,sizeof( st ...