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 }
  • 相关阅读:
    Kprobes—insight into the Linux kernel—replace kernel function with module
    Go将统治下一个十年
    linux—网络仿真开源软件—network simulator—ns
    Serval Project——Android
    CentOS7—Firefox—截图工具—fireshot插件
    Wi-Fi Direct技术
    国产CPU迷局 龙芯该如何参与市场竞争
    《深入理解Android:Wi-Fi,NFC和GPS》—android源码下载
    wifi direct—深入理解Wi-Fi P2P
    c语言学习基础:[1]开发工具介绍
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/5793917.html
Copyright © 2011-2022 走看看