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 ...
随机推荐
- 『ACM C++』 PTA 天梯赛练习集L1 | 027-028
死亡周二,今天去看惊奇队长了!!!真的很佩服国外的后期特效大片技术,要是我们国内也能实现这样的技术能力就好了~ 羡慕max -------------------------------------- ...
- PHP几种常见魔术方法与魔术变量解析
原文地址:http://small.aiweimeng.top/index.php/archives/49.html 先不多说,直接上代码,如下: class Demo { private $str ...
- 虚拟机VMware安装linux无法上网解决办法
虚拟机VMware安装linux无法上网解决办法 Linux网络设置: 依次单击[System]-->[Preferences]-->[Network Connections],如下图 ...
- Wtrofms
一.安装 安装:pip3 install wtforms 二.使用1(登录) from flask import Flask, render_template, request, redirect f ...
- python 3下对stm32串口数据做解析
1.最近有个想做一个传感器数据实时显示的上位机,常规的数据打印太频繁了,无法直观的看出数据的变化. python下的上位机实现起来简单一点,网上找了一些python界面Tkinter相关资料和pyth ...
- 【EXCEL】指定の項目の内容一覧を表示
上記の図の左の部分みたいな長いデータがあって. その中からただほしいのは右側部分ように一部分のみほしい時. 普段はVLOOKUP使用フィルターをかけて探すなどの方法をしようしていますが. ここで.簡単 ...
- SAP 直接修改程序的方法
一般项目上都会有这么个神奇的程序,能在测试机和生产机上直接修改程序... REPORT ztest_change. "变量定义 , line() TYPE c, "如果代码中某行大 ...
- 20155230 实验二《Java面向对象程序设计》实验报告
20155230 实验二<Java面向对象程序设计>实验报告 一.单元测试 三种代码 知道了伪代码.产品代码.测试代码的关系和用途,并根据老师的例子,按测试代码调试了产品代码. 值得注意的 ...
- week14课上测试
说明 本次测试老师将所有课下测试的易错题全部重新考察了一遍,虽然是第二次做,还提前复习过,还是错了很多,回到寝室发现老师还没有结束测试,43分的我又忍不住再做了一遍. 做第二遍发现了有几个题目是蓝墨云 ...
- 20145234黄斐《Java程序设计》第九周
教材学习内容总结 整合数据库 JDBC入门 JDBC是用于执行SQL的解决方案,开发人员使用JDBC的标准接口,数据库厂商则对接口进行操作,开发人员无须接触底层数据库驱动程序的差异性,数据库本身是个独 ...