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 数学的更多相关文章

  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)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  3. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  4. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  5. 暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

    题目传送门 /* 暴力:O (n^2) */ #include <cstdio> #include <algorithm> #include <cstring> # ...

  6. Codeforces Round #368 (Div. 2) C

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

  7. 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 ...

  8. 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 ...

  9. Pythagorean Triples(Codeforces Round #368 (Div. 2) + 构建直角三角形)

    题目链接: https://codeforces.com/contest/707/problem/C 题目: 题意: 告诉你直角三角形的一条边,要你输出另外两条边. 思路: 我们容易发现除2外的所有素 ...

随机推荐

  1. bzoj千题计划187:bzoj1770: [Usaco2009 Nov]lights 燈 (高斯消元解异或方程组+枚举自由元)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1770 a[i][j] 表示i对j有影响 高斯消元解异或方程组 然后dfs枚举自由元确定最优解 #in ...

  2. c#的as,is 运算符

  3. Angular 下的 function

    angular.lowercas 将指定的字符串转换为小写的 Usage(使用方法) angular.lowercase(string);   Arguments Param Type Details ...

  4. 关于如何在Python中使用静态、类或抽象方法的权威指南

    Python中方法的工作方式 方法是存储在类属性中的函数,你可以用下面这种方式声明和访问一个函数 >>> class Pizza(object): ... def __init__( ...

  5. 通俗理解决策树中的熵&条件熵&信息增益

    参考通俗理解决策树算法中的信息增益 说到决策树就要知道如下概念: 熵:表示一个随机变量的复杂性或者不确定性. 假如双十一我要剁手买一件衣服,但是我一直犹豫着要不要买,我决定买这件事的不确定性(熵)为2 ...

  6. 【C++】cmdline——轻量级的C++命令行解析库

    1.说明 cmdline是一个轻量级的c++命令行参数解析工具,全部源码只有一个cmdline.h头文件. 2.代码 20171210_命令行进行解析.cpp // 20171210_命令行进行解析. ...

  7. Linux中断(interrupt)子系统之五:软件中断(softIRQ)

    转自:http://blog.csdn.net/droidphone/article/details/7518428 软件中断(softIRQ)是内核提供的一种延迟执行机制,它完全由软件触发,虽然说是 ...

  8. Shiro:ajax的session超时处理

    本问题解决方案参照网站多篇文章融合解决,在此表示感谢! 环境:springboot+shiro+jquery-easyui 问题:在ajax请求时,如果此时session已经失效,系统没有自动跳转到登 ...

  9. [USACO17FEB]Why Did the Cow Cross the Road I G

    一开始想写$DP$,发现直接转移完全有后效性 所以本小蒟蒻写了个最短路 每走三步就要吃草是这个题最难搞的地方,我们建图时不妨只对于距离等于三的点连边 考虑完全覆盖所有情况,从一个点走一步,两步,然后三 ...

  10. watch案例解析(element-ui el-select 无法选中问题剖析)

    fire 读在最前面: 1.此文章衔接Vue 虚拟Dom 及 部分生命周期初探,相关整体知识点请先阅读后再继续本文阅读 问:子组件中明明有watch value,为什么this.$emit('inpu ...