📜  可以存在正整数个N个因数的最大可能质数除数

📅  最后修改于: 2021-04-22 00:19:57             🧑  作者: Mango

给定整数N表示任意数量的除数的数量,任务是找到具有N个除数的最大可能除数。

例子:

方法:这个想法是找到数字N的素数分解,然后素数除数的幂之和就是N个除数可以具有的最大数个素数除数。

例如:

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

下面是上述方法的实现:

C++
// C++ implementation to find the
// maximum possible prime divisor
// of a number can have N divisors
  
#include 
  
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;
}


Java
// Java implementation to find the
// maximum possible prime divisor
// of a number can have N divisors
import java.util.*;
  
class GFG{
  
// Function to find the 
// maximum possible prime divisors
// of a number can have with N divisors
static 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++;
    }
    System.out.print(max_possible_prime + "\n");
}
  
// Driver Code
public static void main(String[] args)
{
    int n = 4;
      
    // Function Call
    findMaxPrimeDivisor(n);
}
}
  
// This code is contributed by amal kumar choubey


Python3
# Python3 implementation to find the
# maximum possible prime divisor
# of a number can have N divisors
  
# Function to find the maximum 
# possible prime divisors of a 
# number can have with N divisors
def findMaxPrimeDivisor(n):
      
    max_possible_prime = 0
      
    # Number of time number
    # divided by 2
    while (n % 2 == 0):
        max_possible_prime += 1
        n = n // 2
          
    # Divide by other prime numbers
    i = 3
    while(i * i <= n):
        while (n % i == 0):
              
            max_possible_prime += 1
            n = n // i
        i = i + 2
          
    # If the last number of also
    # prime then also include it
    if (n > 2):
        max_possible_prime += 1
      
    print(max_possible_prime)
  
# Driver Code
n = 4
  
# Function Call
findMaxPrimeDivisor(n)
  
# This code is contributed by SHUBHAMSINGH10


C#
// C# implementation to find the
// maximum possible prime divisor
// of a number can have N divisors
using System;
  
class GFG{
  
// Function to find the 
// maximum possible prime divisors
// of a number can have with N divisors
static 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++;
    }
    Console.Write(max_possible_prime + "\n");
}
  
// Driver Code
public static void Main(String[] args)
{
    int n = 4;
      
    // Function Call
    findMaxPrimeDivisor(n);
}
}
  
// This code is contributed by amal kumar choubey


输出:
2