Given a positive integer n, the task is to check if n is a Non-hypotenuse number or not. If n is a Non-hypotenuse number then print ‘YES’ else print ‘NO’.
Non-hypotenuse number : In mathematics, a Non-hypotenuse number is a natural number whose square can not be expressed as sum of two distinct non-zero squares,
i.e a non-hypotenuse number can not be put into the form of (x2 + x2 ) or K(x2 + x2 ) ; where K, x and y are positive integers. The number 1, 2, 3, 4 are Non-hypotenuse number while 5 is not a Non-hypotenuse number.
A Non-hypotenuse number can not be the hypotenuse of the right angled triangle having integer sides.
Explanation: 5 can be expressed as 22 + 12.
Explanation: 6 can not be expressed as sum of two different squares.
First few Non-hypotenuse numbers are-
1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 14, 16, 18, 19, 21, 22, 23, 24, 27, 28, 31, 32, 33, 36, 38, 42, 43, 44, 46, 47
A Simple Solution to check if the given number ‘n‘ is a Non-Hypotenuse number or not is to check if any combination of squares of x and y is equal to n or not.
A Efficient Solution is based on the fact that a non-hypotenuse number do not have any prime factor of the form 4k+1.
Explanation: Prime factors of 12 is 2 and 3. None of them is of the form 4k+1
Explanation: Prime factors of 10 is 2 and 5. Here 5 is of the form 4k+1
- Find all prime factors of n
- Check if any prime factor of is of the form 4k+1 or not.
- Print ‘YES’ if none of the factor is of the form 4k+1
Else print ‘NO’
To read more about method of calculating prime factor of any number, refer this.
Below is the implementation of above approach-
2 && ($n – 1) % 4 == 0)
echo “Testing for “, $n , ” : “;
echo “YES”. “\n”;
echo “NO”. “\n”;
// Driver code
$n = 11;
$n = 10;
// This code is contributed by Sach_Code
Testing for 11 : YES Testing for 10 : NO
- Check if a number is divisible by all prime divisors of another number
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Program to check whether a number is Proth number or not
- Check if a number with even number of digits is palindrome or not
- Check if a number is a Trojan Number
- Check if a number is a Mystery Number
- Check if a number is an Achilles number or not
- Check if a number is an Unusual Number or not
- How to check if a given number is Fibonacci number?
- Check if a number is a power of another number
- Check if given number is Emirp Number or not
- Check Whether a number is Duck Number or not
- Check if a number is Triperfect Number
- Check if a number is a Krishnamurthy Number or not
- Check whether the given number is Euclid Number or not