题目链接:

  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. python版本简历

  2. heibernate增删改查总结一下自己的不足

    难点也就我不熟悉的是数据库语句的书写,要加强复杂查询语句的书写 /* 简单的在共享类中已经可以用的了 * 总结: * * --------------------------------------查 ...

  3. Html网页生成Pdf

    在http://code.google.com/p/wkhtmltopdf/downloads/list下载安装程序. 1.添加引用 using System.Diagnostics; 添加引用 2. ...

  4. Datum Form Goole Android

    1. <TurboChargeYourUI-How to make your AndroidUI fast and efficient> 2. <The World of List ...

  5. 强大的Core Image框架,各种滤镜处理图像

    首先介绍一下Core Image,他是一个很强大的图像处理框架,他可以让你简单的应用各种滤镜来处理图像,比如说色相,饱和度,亮度等等...他是运用GPU(CPU)实时地处理图像数据和视频的帧.而且Co ...

  6. C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse

    上次介绍了用WebClient的方式提交POST请求,这次,我继续来介绍用其它一种方式 HttpWebRequest以及HttpWebResponse 自认为与上次介绍的WebClient最大的不同之 ...

  7. Jquery 点击空白处消失

    $(document).bind("click", function (e){ if ( $((e.target || e.srcElement)).closest("# ...

  8. 安装完 MySQL 后必须调整的 10 项配置

    原文出处: mysqlperformanceblog   译文出处:开源中国   欢迎分享原创到伯乐头条 当我们被人雇来监测MySQL性能时,人们希望我们能够检视一下MySQL配置然后给出一些提高建议 ...

  9. CPU风扇故障导致自动关机

    今天在使用电脑时,突然自动关机,重启后过一段时间又自动关机,于是打开机箱后盖,插上电源观察各个部位运行情况,发现CPU风扇不转,判断问题就是由于CPU温度太高了.于是换个风扇,再开机情况就正常了.

  10. An erroroccurred while filtering resources

    maven报错: maven An error occurred while filtering resources Maven -> Update Project... resolved th ...