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中如何动态创建接口的实现
    使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
    MyBatis中的@Mapper注解及配套注解使用详解(上)
    SpringMVC-DispatcherServlet工作流程及web.xml配置
    SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
    Spring MVC 配置文件dispatcher-servlet.xml 文件详解
    python3 UnicodeEncodeError: 'gbk' codec can't encode character 'xa0' in position 30: illegal multibyte sequence
    python3之日期和时间(转载)
    python3 操作sqlSever
    python 抓取alexa数据
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/5793917.html
Copyright © 2011-2022 走看看