VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-if-the-given-number-is-ore-number-or-not/

โ‡ฑ Check if the given number is Ore number or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if the given number is Ore number or not

Last Updated : 11 Jul, 2025

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- 
 

๐Ÿ‘ Harmonic mean of 6


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. 

๐Ÿ‘ Image

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. 

  1. Generate All Divisors of the given number - 'n'
  2. Calculate the Harmonic mean of the divisors of n
  3. Check if the Harmonic mean is an Integer or not
  4. If Yes, Then the number is an Ore Number otherwise Not

Below is the implementation of the above approach: 


Output
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

Comment