【题目链接】:http://codeforces.com/contest/707/problem/C

【题意】

给你一个数字n;
问你这个数字是不是某个三角形的一条边;
如果是让你输出另外两条边的大小;

【题解】

首先明确n<=2的时候是无解的。
n>2之后都有解;
这里设
n2+b2=a2
则有
n2=a2−b2
也即
n2=(a+b)∗(a−b)
这里对n分两类讨论;

n为奇数
则令
a−b=1
a+b=n2
这样
2∗a=n2+1
因为n是奇数所以右边是个偶数;
得出来的a就是整数了符合题意;
然后b=a-1

n为偶数
则令
a−b=2
a+b=n2/2

2∗a=n2/2+2
a=n2/4+1
因为n是大于2的偶数,所以a最后得到的结果是个整数且大于2;
b=a-2;

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)typedef pair<int, int> pii;
typedef pair<LL, LL> pll;const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110;LL n;
LL sqr(LL x) { return x*x; }int main(){//freopen("F:\\rush.txt", "r", stdin);rel(n);if (n <= 2) return puts("-1"), 0;if (n & 1){LL b = (sqr(n) + 1) / 2;LL a = b - 1;printf("%lld %lld\n", a, b);}else{LL b = sqr(n) / 4 + 1;LL a = b - 2;printf("%lld %lld\n", a, b);}//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);return 0;
}

【codeforces 707C】Pythagorean Triples相关推荐

  1. 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

    题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...

  2. 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

    题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...

  3. 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

    题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...

  4. 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)

    题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...

  5. 【CodeForces 997C】Sky Full of Stars(组合计数)

    题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...

  6. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  7. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  8. 【codeforces 711B】Chris and Magic Square

    [题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...

  9. 【codeforces 807C】Success Rate

    [题目链接]:http://codeforces.com/contest/807/problem/C [题意] 给你4个数字 x y p q 要求让你求最小的非负整数b; 使得 (x+a)/(y+b) ...

最新文章

  1. WordPress工作原理之程序文件执行顺序
  2. JavaScript 编程精解 中文第三版 十一、异步编程
  3. 从命令式到响应式(四)
  4. dependency报红_解决IDEA中Maven依赖包导入失败报红问题(总结最有效8种解决方案)...
  5. java io中断_JDK源码阅读:InterruptibleChannel 与可中断 IO
  6. php中的Register Globals
  7. 解决 git pull/push 每次都要输入用户名密码的问题
  8. (十一)C语言中内存堆和栈的区别
  9. 禁用vsftpd欢迎语
  10. C#基础精华05(正则表达式,)
  11. TeamViewer开机自启动实现在远程使用时重启远程计算机
  12. mysql 递归查询子类_MySQL递归查询当前节点及子节点
  13. 基于51单片机的12864液晶显示4X4矩阵键盘程序仿真
  14. 无模拟电路基础如何看TTL电路
  15. OSEK网络管理入门
  16. 一线协议—ds18b20
  17. 人工智能——单层感知器
  18. 怎么样把谷歌浏览器的默认背景颜色设置成绿豆沙
  19. 理科生学酒店管理好一点还是计算机,酒店管理专业是文科还是理科
  20. 社群运营,日常社群管理有哪些要点?

热门文章

  1. Installation failed due to: ‘‘cmd package install-create -r -t --user current --full --dont-kill -t
  2. 自定义模块上传 npmjs.com 过程
  3. Deadline渲染管理系统
  4. Vue 项目如何进行 SEO 优化
  5. 浅谈区块链的格局审视和被遗忘的权利
  6. python输入三门课程成绩_编一程序,从键盘输入学生的三门课程成绩,求其总成绩、平均成绩和总成绩除3的余值...
  7. phhphphphphphphp转自 细雪之舞 专注DEV
  8. 团队环境搭建:MTK平台,PTK5.1、Supernova编译环境配置
  9. 播放器实战22 解决花屏与卡顿问题
  10. wkhtmltopdf下载pdf有个别字体是乱码