Codeforces Problem 707C Pythagorean triples (math) __ACM

Source: Internet
Author: User
Tags time limit

This article can use the directory features yo ↑ (click above [+])

Game links →codeforces Round #368 (Div. 2)

codeforces Problem 707C Pythagorean triples

accept:0 submit:0
Time Limit:1 second Memory limit:256 megabytes
Problem 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 so you can construct a right triangle with segments of Len Gths corresponding to triple. Such triples are called Pythagorean triples.

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

Here Katya wondered if she can specify the length of some side to right triangle and find any Pythagorean triple Correspon Ding to such length? Note this side which length is specified can be a cathetus as as as. Hypotenuse.

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

Input

The only line of this input contains single integer n (1≤n≤10^9)-the length of some side to right triangle.
Output

Print two integers m and K (1≤m, k≤10^18), such that N, M. and K form a Pythagorean triple, in the only line.

In case if there be no any Pythagorean triple containing integer n, print-1 in the only line. If There are many answers, print any of them.
Sample Input 3
6
1
17
Sample Output 4 5
8 10
-1
144 145
2244 2245 Hint


Illustration for the.

Problem Idea

Ideas for solving problems:

Meaning
give you a number n, ask if there are another two number a,b, so that these three numbers exactly constitute the three sides of a right triangle


Type
Math problems

Analysis
For the right-angled triangle ABC, as shown in figure:


What we know is that


Because the title says if there are multiple solutions to the problem, output any one can be, so we might as well assume that the input of n is a rectangular length of the edge, then


According to the square difference formula can be


So, this time, what we're going to solve is a,b.

So, we can sort of discuss


"Time Complexity && optimization"
O (1)

Topic link →codeforces Problem 707C Pythagorean triples Source Code

/*sherlock and Watson and adler*/
#pragma comment (linker, "/stack:1024000000,1024000000")
#include < stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <map>
#include < set>
#include <cmath>
#include <complex>
#include <string>
#include < algorithm>
#include <iostream>
#define EPS 1e-9
#define LL long
#define PI ACOs (-1.0 )
#define BITNUM (a) __builtin_popcount (a)
using namespace std;
const int N = 100005;
const int M =;
const int inf = 1000000007;
const int mod = 1000000007;
int main ()
{
    __int64 n,a,b;
    scanf ("%i64d", &n);
    if (n==1| | n==2)
        puts ("-1");
    else if (n*n%2)
        printf ("%i64d%i64d\n", (n*n-1)/2, (n*n+1)/2);
    else
        printf ("%i64d%i64d\n", (n*n/2-2)/2, (n*n/2+2)/2);
    return 0;
}
Rookie Grow up Remember

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.