![]() |
VOOZH | about |
Given a positive integer n, check if it is an Ore number or not. Print 'YES' if n is an ore number otherwise print 'NO'.
Ore Number: In mathematics, Ore numbers are positive integers whose divisors have an integer harmonic value. Ore numbers are often called harmonic divisor numbers. Ore numbers are named after รystein Ore.
For example, 6 has four divisors namely 1, 2, 3, and 6.
The harmonic mean of the divisors is-
The harmonic mean of divisors of 6 is 2, an integer. So, 6 is an Ore number or harmonic divisor number.
First, a few Ore numbers or harmonic divisor numbers are:
1, 6, 28, 140, 270, 496, 672, 1638, 2970, 6200, 8128, 8190
Examples:
Input : N = 6 Output : Yes Input : N = 4 Output: No Explanation : Harmonic mean of divisors of 4 is not an Integer.
Prerequisite:
The idea is to generate all divisors of the given number and then check if the harmonic mean of the divisor is an Integer or not.
Below is the implementation of the above approach:
YES
Time Complexity: O(sqrt(n)), Where n is the given number.
Auxiliary Space: O(sqrt(n)), for storing the divisor of n in the array