题目链接:

  http://codeforces.com/problemset/problem/707/C

题目大意:

  给你一个数,构造其余两个勾股数。任意一组答案即可,没法构造输出-1.

  答案long long 范围。

题目思路:

  【数学】

  这里贴一下勾股数的构造:

  当a为大于1的奇数2n+1时,b=2n2+2n, c=2n2+2n+1。
  实际上就是把a的平方数拆成两个连续自然数,例如:
  n=1时(a,b,c)=(3,4,5)
  n=2时(a,b,c)=(5,12,13)
  n=3时(a,b,c)=(7,24,25)
  当a为大于2的偶数2n时,b=n2-1, c=n2+1

  也就是把a的一半的平方分别减1和加1,例如:
  n=2时(a,b,c)=(4,3,5)
  n=3时(a,b,c)=(6,8,10)
  n=4时(a,b,c)=(8,15,17)
  n=5时(a,b,c)=(10,24,26)
  n=6时(a,b,c)=(12,35,37)
 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 100004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
LL a,b,c;
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s+1))
while(~scanf("%I64d",&a))
{
if(a<)puts("-1");
else if(a%)
{
a=a/;
b=*sqr(a)+*a;
c=*sqr(a)+*a+;
printf("%I64d %I64d\n",b,c);
}
else
{
a/=;
b=sqr(a)-;
c=sqr(a)+;
printf("%I64d %I64d\n",b,c);
}
}
return ;
}
/*
// //
*/

【数学】Codeforces 707C Pythagorean Triples的更多相关文章

  1. CodeForces 707C Pythagorean Triples

    数学,构造. 这题比较有意思,一开始没发现结论写了一个最坏复杂度为$O({10^9})$暴力居然能$AC$,正因为如此,我才发现了规律. 一开始是这么想的: 先假设$n$为直角边,设斜边长度为$c$, ...

  2. Codeforces 707C Pythagorean Triples(构造三条边都为整数的直角三角形)

    题目链接:http://codeforces.com/contest/707/problem/C 题目大意:给你一条边,问你能否构造一个包含这条边的直角三角形且该直角三角形三条边都为整数,能则输出另外 ...

  3. CodeForces 707C Pythagorean Triples (数论)

    题意:给定一个数n,问你其他两边,能够组成直角三角形. 析:这是一个数论题. 如果 n 是奇数,那么那两边就是 (n*n-1)/2 和 (n*n+1)/2. 如果 n 是偶数,那么那两边就是 (n/2 ...

  4. Codeforces 707C. Pythagorean Triples-推公式的数学题

    两道C题题解,能推出来公式简直是无敌. http://codeforces.com/problemset/problem/707/C codeforces707C. Pythagorean Tripl ...

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

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

  6. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

  7. Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

    C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...

  8. Pythagorean Triples 707C

    Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theor ...

  9. Pythagorean Triples毕达哥斯拉三角(数学思维+构造)

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

随机推荐

  1. NP-难题

    所谓NP-难题,在给定的一个信息系统中,假设研究对象书目为m,属性书目为n,则要考察的属性集P的一个子集是否为最小子集,要进行n*m*m次的比较.而n个属性可构成2的n次方个子集,这些子集都有可能是最 ...

  2. Java_Activiti5_菜鸟也来学Activiti5工作流_之入门简单例子(一)

    // VacationRequest.java /** * author : 冯孟活 ^_^ * dates : 2015年9月1日 下午10:32:58 * class : 演示简单的公司请假流程 ...

  3. 监听polygon变化

    Polygons are made of Paths which are just MVCArrays (in this case, they're a list of LatLng objects) ...

  4. SQL Server死锁日志各字段含义

    使用跟踪标记 1204 --打开跟踪标记 DBCC TRACEON (1204,-1) --关闭跟踪标记 DBCC TRACEOFF (1204,-1) 处于死锁状态时,跟踪标记 1204 在等待的线 ...

  5. eclipse中修改内存

  6. C#入门经典(第五版)学习笔记(二)

    ---------------函数---------------参数数组:可指定一个特定的参数,必须是最后一个参数,可使用个数不定的参数调用函数,用params关键字定义它们 例如: static i ...

  7. 344. Reverse String(C++)

    344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...

  8. 【HOJ2430】【贪心+树状数组】 Counting the algorithms

    As most of the ACMers, wy's next target is algorithms, too. wy is clever, so he can learn most of th ...

  9. Java发邮件:Java Mail与Apache Mail

    作者:Vinkn 来自http://www.cnblogs.com/Vinkn/ 一.邮件简介 一封邮件由很多信息构成,主要的信息如下,其他的暂时不考虑,例如抄送等: 1.收件人:收件人的邮箱地址,例 ...

  10. 用css3实现鼠标移进去当前亮其他变灰

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...