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 ...
随机推荐
- Python 分支、循环、条件、枚举
对于表达式,分为“左结合”和“右结合” 左结合:对于没有 = 号的,从左到右边,当然要考虑优先级. 右结合:对于有 = 号存在的情况,右边的自成一体,然后赋值给左边变量 优先级: 逻辑运算符的优先 ...
- hiveSql常见错误记录
1. In strict mode, if ORDER BY is specified, LIMIT must also be specified. 这个错误提示是因为在hive下写的sql使用了or ...
- windows10 通过命令行来查看wifi密码
c:\Windows\System32>netsh netsh>wlan show profile 接口 WLAN 上的配置文件: 组策略配置文件(只读) ---------------- ...
- jquery实现复选框的全选、全不选、反选
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 创建Podfile,添加类库,中途添加库指令
前提是你电脑已经安装了CocoaPods 1.打开终端 2.进入你的工程目录 cd /Users/...../CocoaPodsDemo 3. 创建Pods文件 touch Podfile 新建 ...
- Hadoop系列-HDFS基础
基本原理 HDFS(Hadoop Distributed File System)是Hadoop的一个基础的分布式文件系统,这个分布式的概念主要体现在两个地方: 数据分块存储在多台主机 数据块采取冗余 ...
- python写爬虫时的编码问题解决方案
在使用Python写爬虫的时候,常常会遇到各种令人抓狂的编码错误问题.下面给出一些简单的解决编码错误问题的思路,希望对大家有所帮助. 首先,打开你要爬取的网站,右击查看源码,查看它指定的编码是什么,如 ...
- 5.18-笨办法学python-习题15(open等读取文件)
from sys import argv script,filename=argv #不要忘了script(相当于一个固定变量),filename(可变变量) txt=open(filename) # ...
- Python之路(四)--->list、元组、字典
好久没有更新了,感觉自己写的东西并没有太多人看,可能是因为写的不好,也可能是太基础了.学习是一个漫长的过程,结果结果固然重要,但是更重要的是在学习的过程中所学到方法,这些方法在以后的生活还是工作中都能 ...
- 关于NODEJS性能测试和优缺点总结
最近公司开发了一套新产品,采用nodejs前端+Java后端框架,为完全的前后端分离结构,以下为相关信息. 软件及功能: 软件 功能 Nginx 负责反向代理和负载均衡 Nodejs 前端代码 JDK ...