# 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 = 2^{2}Sum of powers of prime factors = 2

Below is the implementation of the above approach:

## C++

`// 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*

*filter_none*

**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

## Recommended Posts:

- Sum of all prime divisors of all the numbers in range L-R
- Count of numbers below N whose sum of prime divisors is K
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Find sum of divisors of all the divisors of a natural number
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Sum of all the prime divisors of a number
- Count of the non-prime divisors of a given number
- Generating all divisors of a number using its prime factorization
- Check if a number can be expressed as a product of exactly K prime divisors
- Numbers with exactly 3 divisors
- Check if sum of divisors of two numbers are same
- Common Divisors of Two Numbers
- Sum of common divisors of two numbers A and B
- Common divisors of N numbers

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.