zoukankan      html  css  js  c++  java
  • codeforces707C:Pythagorean Triples

    Description

    Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are calledPythagorean triples.

    For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.

    Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.

    Katya had no problems with completing this task. Will you do the same?

    Input

    The only line of the input contains single integer n (1 ≤ n ≤ 109) — the length of some side of a right triangle.

    Output

    Print two integers m and k (1 ≤ m, k ≤ 1018), such that nm and k form a Pythagorean triple, in the only line.

    In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.

    Examples
    input
    3
    output
    4 5
    input
    6
    output
    8 10
    input
    1
    output
    -1
    input
    17
    output
    144 145
    input
    67
    output
    2244 2245



    正解:数学(数论)
    解题报告:
      n<=2显然无解。
      若n为奇数,则另两个为(a*a-1)/2和(a*a+1)/2;
      若n为偶数,则另两个为(a/2)*(a/2)-1和(a/2)*(a/2)+1

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<algorithm>
     7 using namespace std;
     8 typedef long long LL;
     9 LL n;
    10 LL a,b;
    11 
    12 inline int getint(){
    13     int w=0,q=1;char c=getchar();
    14     while(c!='-' && (c<'0' || c>'9')) c=getchar();
    15     if(c=='-') q=-1,c=getchar();
    16     while(c>='0' && c<='9') w=w*10+c-'0',c=getchar();
    17     return w*q;
    18 }
    19 
    20 int main()
    21 {
    22     n=getint();
    23     if(n<=2) printf("-1");
    24     else if(n&1) {
    25     a=n*n-1; a/=2; b=a+1;
    26     printf("%I64d %I64d",a,b);
    27     } 
    28     else {
    29     n/=2;
    30     a=n*n-1; b=n*n+1;
    31     printf("%I64d %I64d",a,b);
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    Java实现蓝桥杯 九宫幻方
    Java实现蓝桥杯 九宫幻方
    Java实现蓝桥杯 九宫幻方
    Java实现蓝桥杯 九宫幻方
    Java实现蓝桥杯 历届试题 合根植物
    dddd
    隋唐英雄第70集和第90集的片头真有意思
    造成远程文件大小为零的原因(索引值里变成了0)
    QDataStream类参考(串行化数据,可设置低位高位,以及版本号),还有一个例子
    房价收入比大幅攀升,已经达到足以傲视全球的境界,这已是大家的共识(好几段评论都非常精彩)
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/5793917.html
Copyright © 2011-2022 走看看