Codeforces Round #368 (Div. 2) C. Pythagorean triples (Right angle)

Source: Internet
Author: User
Tags printf time limit


C. Pythagorean Triples
Time limit per test1 second
Memory limit per test256 megabytes
Inputstandard input
Outputstandard output
Katya Studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there is triples of positive integers such that's can construct a right triangle with segments of Len Gths corresponding to triple. Such triples is called Pythagorean triples.



For example, triples (3, 4, 5), (5,,) and (6, 8, ten) are Pythagorean triples.



Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple Correspon Ding 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. Would 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 integers m and K (1≤m, k≤1018), such that N, M and K form a Pythagorean triple



If there is no any Pythagorean triple containing integer n, print-1 If There is 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
Note


Illustration for the first sample.




Test instructions: give the edge length n, find the other two side length m,k, make the triangle with n,m,k as the edge length satisfies the Pythagorean theorem. For an n, find any set of solutions, if there is no solution then output-1



Ideas
N*n+m*m=k*k;
K*k-m*m=n*n;
(k+m) (k-m) =n*n;
If N*n is an even number
K+m=n*n/2
k-m=2
If N*n is an odd number
K+m=n*n
K-m=1
A set of solutions can be found by solving a two-dollar equation group at a time.



Pay attention to the n<=2 of the special sentence



Code



#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h >
#include <queue>
using namespace std;
int main ()
{
    long long int A;
    scanf ("%i64d", &a);
    if (a<=2)
        printf (" -1\n");
    else
    {
        if (a*a%2==0)
            printf ("%i64d%i64d\n", (a*a-4)/4, (a*a-4)/4+2);
        else
            printf ("%i64d%i64d\n", (a*a-1)/2, (A*a-1)/2+1);
    }
    return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.