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 }
  • 相关阅读:
    ZJOI2019二轮游记
    Luogu P5284 [十二省联考2019]字符串问题
    Luogu P5309 [Ynoi2012]D1T1
    Luogu P5292 [HNOI2019]校园旅行
    LOJ #6052. 「雅礼集训 2017 Day11」DIV
    Luogu P5279 [ZJOI2019]麻将
    LOJ #6060. 「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set
    Luogu P5283 [十二省联考2019]异或粽子
    Luogu P5290 [十二省联考2019]春节十二响
    Luogu P5285 [十二省联考2019]骗分过样例
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/5793917.html
Copyright © 2011-2022 走看看