【题目链接】: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 707C】Pythagorean Triples(找规律)

    一边长为a的直角三角形,a^2=c^2-b^2.可以发现1.4.9.16.25依次差3.5.7.9...,所以任何一条长度为奇数的边a,a^2还是奇数,那么c=a^2/2,b=c+1.我们还可以发现, ...

  2. codeforces 707C C. Pythagorean Triples(数学)

    题目链接: C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. map的遍历方式(使用Junit测试)

    package cn.sdut.lah; import java.util.HashMap; import java.util.Iterator; import java.util.Map; impo ...

  2. 洛谷 P4180 【模板】严格次小生成树[BJWC2010]【次小生成树】

    严格次小生成树模板 算法流程: 先用克鲁斯卡尔求最小生成树,然后给这个最小生成树树剖一下,维护边权转点权,维护最大值和严格次大值. 然后枚举没有被选入最小生成树的边,在最小生成树上查一下这条边的两端点 ...

  3. python使用ddt模块对用例执行操作

    import time import unittest import ddt from selenium import webdriver TEST_URL = "http://www.ba ...

  4. CodeIgnitor 配置类的使用

    CI 的配置文件统一放在 application/config/ 目录下面,框架有一个默认的主配置文件 application/config/config.php.其部分内容如下: <?php ...

  5. 51nod 1166 大数开平方

    1166 大数开平方 基准时间限制:4 秒 空间限制:131072 KB 分值: 320 难度:7级算法题  收藏  关注 给出一个大整数N,求不大于N的平方根的最大整数.例如:N = 8,2 * 2 ...

  6. 三分 POJ 2420 A Star not a Tree?

    题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...

  7. 6.12---esultMap查询所有

  8. rabbitmq 简单示例(Hello World)

    一:消息中间件: AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计 RabbitMQ是实现AMQP( ...

  9. JS高级——文件操作

    https://www.cnblogs.com/mingmingruyuedlut/archive/2011/10/12/2208589.html https://blog.csdn.net/pl16 ...

  10. setTimeout 0

    setTimeout 0 就是把事件放到下一次事件循环时调用,至少要一个时钟之后: ); console.log('this should before setTimeout 0'); var i=0 ...