Maximum possible prime divisors that can exist in numbers having exactly N divisors

Given an integer N which denotes the number of divisors of any number, the task is to find the maximum prime divisors that are possible in number having N divisors.

Examples:

Input: N = 4
Output: 2



Input: N = 8
Output: 3

Approach: The idea is to find the prime factorization of the number N, then the sum of the powers of the prime divisors is the maximum possible prime divisors of a number can have with N divisors.

For Example:

Let the number of divisors of number be 4,

Then the possible numbers can be 6, 10, 15,...
Divisors of 6 = 1, 2, 3, 6

Total number of prime-divisors = 2 (2, 3)

Prime Factorization of 4 = 22
Sum of powers of prime factors = 2

Below is the implementation of the above approach:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ implementation to find the
// maximum possible prime divisor
// of a number can have N divisors
  
#include <iostream>
  
using namespace std;
  
#define ll long long int
  
// Function to find the 
// maximum possible prime divisors
// of a number can have with N divisors
void findMaxPrimeDivisor(int n){
      
    int max_possible_prime = 0;
  
    // Number of time number
    // divided by 2
    while (n % 2 == 0) {
        max_possible_prime++;
        n = n / 2;
    }
  
    // Divide by other prime numbers
    for (int i = 3; i * i <= n; i = i + 2) {
        while (n % i == 0) {
            max_possible_prime++;
            n = n / i;
        }
    }
  
    // If the last number of also
    // prime then also include it
    if (n > 2) {
        max_possible_prime++;
    }
  
    cout << max_possible_prime << "\n";
}
  
// Driver Code
int main()
{
  
    int n = 4;
      
    // Function Call
    findMaxPrimeDivisor(n);
    return 0;
}

chevron_right


Output:

2

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.