Return to Snippet

Revision: 50682
at August 30, 2011 06:23 by FMalk


Initial Code
/// <summary>
/// Find how many factors there is in N for a prime P
/// </summary>
static int multiplicity(int n, int p)
{
    int q = n, m = 0;
    if (p > n) return 0;
    if (p > n / 2) return 1;
    while (q >= p)
    {
        q /= p;
        m += q;
    }
    return m;
}

Initial URL

                                

Initial Description
Find how many factors there is in N! for a prime P
Ex: 5! = (2^3)*(3^1)*(5^1)
mult(5,2) = 3
mult(5,3) = 1
mult(5,5) = 1
all else = 0

Initial Title
Factorial prime numbers factorization

Initial Tags
number

Initial Language
C#