Answers for "Finding power of prime number p in n!"

C
1

Finding power of prime number p in n!

int PowerOFPINnfactorial(int n, int p) 
{ 
    // initializing answer 
    int ans = 0; 
  
    // initializing 
    int temp = p; 
  
    // loop until temp<=n 
    while (temp <= n) { 
  
        // add number of numbers divisible by n 
        ans += n / temp; 
  
        // each time multiply temp by p 
        temp = temp * p; 
    } 
    return ans; 
}
Posted by: Guest on September-25-2021

Code answers related to "Finding power of prime number p in n!"

Code answers related to "C"

Browse Popular Code Answers by Language