Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学
C. Pythagorean Triples
题目连接:
http://www.codeforces.com/contest/707/problem/C
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
Sample Output
4 5
Hint
题意
给你直角三角形的一边长度,让你找到两个整数,是其他两条边的边长,问你能否找到。
题解:
其实是公式题,随便百度了一下,就找到结论了= =
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
if(n<=2){
cout<<"-1"<<endl;
return 0;
}
if(n%2)
{
long long a=(n-1LL)/2LL;
cout<<2LL*a*a+2LL*a<<" "<<2LL*a*a+2LL*a+1LL<<endl;
return 0;
}
else
{
long long a=n/2;
cout<<a*a-1<<" "<<a*a+1<<endl;
}
}
Codeforces Round #368 (Div. 2) C. 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)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- 暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II
题目传送门 /* 暴力:O (n^2) */ #include <cstdio> #include <algorithm> #include <cstring> # ...
- Codeforces Round #368 (Div. 2) C
Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...
- Codeforces Round #368 (Div. 2)A B C 水 图 数学
A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #368 (Div. 2) A , B , C
A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Pythagorean Triples(Codeforces Round #368 (Div. 2) + 构建直角三角形)
题目链接: https://codeforces.com/contest/707/problem/C 题目: 题意: 告诉你直角三角形的一条边,要你输出另外两条边. 思路: 我们容易发现除2外的所有素 ...
随机推荐
- li分两列显示
只要控制了li的宽度,利用浮动就能实现<style type="text/css"> .my ul { width: 210px; } .my li { width: ...
- js 正则之 检测素数
相信很多人应该看过这篇文章,我第一次看到的时候是11年的样子,那时候学vbs的时候看过这个问题.原文<检查素数的正则表达式>,在文章里已经解释了他是怎么判断的,我就不啰嗦了.我们来说说 j ...
- 一个很实用的css3兼容工具很多属性可以兼容到IE6
当你看到这样的效果图是不是已经崩溃了 css3没出来之前大部分人基本都是用图片的方式拼出来的 腾讯邮箱就是这么做的 然后你想和设计说换直角吧.我用图片的好烦的感觉!而且我们还要兼容到ie6 她和你说别 ...
- 微信公众号用户OpenID同步导出系统
一.简介 同步公众账号用户信息,包括OpenID.昵称.头像.地区等. 二.主要功能 同步公众账号用户 OpenID,以及昵称.头像.性别.地区.关注时间等,支持认证订阅号.认证服务号. 支持超过1万 ...
- 在OS X 10.9配置WebDAV服务器联合NSURLSessionUploa…
CHENYILONG Blog 在OS X 10.9配置WebDAV服务器联合NSURLSessionUploadTask实现文件上传iOS7推出的NSURLSession简化了NSURLConn ...
- 第11月第21天 php引用 codeigniter cakephp
1. class CI_Controller { private static $instance; /** * Constructor */ public function __construct( ...
- Windows中用“ls”命令
解决办法是: 在C:\Windows\System32目录下新建文本文档,文件内容为: @echo off dir 另存为“ls.bat” 类型为所有文件,编码ANSI 可使用dir 或者ls都可以 ...
- C++ socket 网络编程 简单聊天室
操作系统里的进程通讯方式有6种:(有名/匿名)管道.信号.消息队列.信号量.内存(最快).套接字(最常用),这里我们来介绍用socket来实现进程通讯. 1.简单实现一个单向发送与接收 这是套接字的工 ...
- 【C语言】十六进制形式输出应用程序
1.前言 最近在看到同事写了一款封印病毒的程序,非常有意思!原理大致是将PE文件中的ASCII转换成HEX输出到文本中.这样做的目的是为了保存病毒样本的时候不会被杀毒软件查杀!然而却是delphi写的 ...
- IIS 无法识别的属性“targetFramework”---解决之道
在安装VS2010后,应用.NET Framework 4创建的网站放在IIS(7.0)下会出现如下的错误: 其中的“版本信息”中告诉了我们.NET Framework和ASP.NET的版本都是2.0 ...