题目链接:

  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. 关于HTTP请求报文和响应报文学习笔记

    超文本传输协议(Hypertext Transfer Protocol,简称HTTP)是应用层的一种通信协议.它是一种请求/响应式的协议,即一个客户端与服务器建立连接后,向服务器发送一个请求;服务器接 ...

  2. spring 定时任务的 执行时间设置规则

    单纯针对时间的设置规则org.springframework.scheduling.quartz.CronTriggerBean允许你更精确地控制任务的运行时间,只需要设置其cronExpressio ...

  3. hdu 3450 Counting Sequences

    /* n*n暴力 这个很好想 */ #include<cstdio> #define maxn 100010 #define mod 9901 using namespace std; i ...

  4. @ManyToMany中间表附加字段设计

    在使用@ManyToMany时,若中间表只有相应的外键字段可以直接建立两个对应的Entity 设置ManyToMany @ManyToMany 两个表多对多关联 但若是中间表有自己的附加字段,这需要为 ...

  5. 怎样使用svn开发项目

    那么首先什么是svn呢?官方有很好的解释,我说一下个人简单的理解,svn就是开源的版本控制软件, 那么什么是版本呢?简单的说版本就是标记,比如你买了一本书,同样的书名,但是版本不一定一样, 因为里面可 ...

  6. logic:present 和 logic:empty的用法 (转)

    logic:empty和logic:notEmpty logic:empty标签判断脚本变量是否为null,是否是一个空的字符串(长度为0),是否是一个空的collection或map(调用isEmp ...

  7. Java 最简单的批处理

    批处理Batch && PreparedStatement : import java.sql.*; public class TestBatch { public static vo ...

  8. 关于mssql数据库锁和事务隔离级别

    事务隔离级别有4种,这4种级别只是对于读操作,也就是select有不同程度的支持, 读未提交:不会对事务里读出来的数据附加任何锁 读已提交:会对事务里读出来的数据附加共享锁,读完就释放共享锁,其他事务 ...

  9. oracle中用comment on的用法

    oracle中用comment on命令给表或字段加以说明,语法如下:COMMENT ON  { TABLE [ schema. ]    { table | view }  | COLUMN [ s ...

  10. DB2JAVIT:RC=9505解决方案

    DB2JAVIT:RC=9505解决方案 题记:WIN7下装DB2,启动任务中心.控制中心报DB2JAVIT:RC=9505. 解决方案:进入(计算机—>管理—>本地用户和组)把用户加入到 ...