Given a single integer n [1, 1000000000], generate a pythagoras triplet with includes n as of it’s sides if possible.
Input : 22 Output : Pythagoras Triplets exist i.e. 22 120 122 Input : 4 Output : Pythagoras Triplets exist i.e. 4 3 5 Input : 2 Output : No Pythagoras Triplet exists
Definition: “Pythagorean triplets” are integer solutions to the Pythagorean Theorem, i.e. they satisfy the equation
Our task is to generate a triplet from an integral value. This can be a confusing task because, the side given to us can be a hypotenuse or a non-hypotenuse side.
Starting to calculate triplets by putting them in a formula, it can be deduced that only for 1 and 2, no triplets are possible.
if n is even, our triplets are calculated by formula
if n is odd, our triplets are calculated by formula
Pythagoras Theorem can also be written as
i.e a*a = (c-b)(c+b)
a*a x 1 = a*a, thus and , this solution works if n is odd.
For even solution, , thus, we get the above formula when n is even.
Pythagoras Triplets exist i.e. 22 120 122
- Generate all unique partitions of an integer
- Generate integer from 1 to 7 with equal probability
- Pythagorean Triplet with given sum
- Prime Triplet
- Triplet with no element divisible by 3 and sum N
- Sum of multiplication of triplet of divisors of a number
- Find a triplet in an array whose sum is closest to a given number
- Finding a Non Transitive Coprime Triplet in a Range
- Count triplet pairs (A, B, C) of points in 2-D space that satisfy the given condition
- Maximum no. of apples that can be kept in a single basket
- Find single Movement in a Matrix
- Sum of Digits in a^n till a single digit
- Reduce the array to a single element with the given operation
- Finding sum of digits of a number until sum becomes single digit
- Solve the Linear Equation of Single Variable
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.