Int get powers(n, p)

From Algorithmist
Jump to: navigation, search
This is a stub or unfinished. Contribute by editing me.

Explanation[edit]

The exponent of a prime p in n! is \sum _{{k=1}}^{{\lfloor log_{p}N\rfloor }}\lfloor {\frac  {N}{p^{{k}}}}\rfloor

Implementation[edit]

int get_powers(int n, int p)
{
    int res = 0;
    for (int power = p ; power <= n ; power *= p)
        res += n/power;
    return res;
}


See[edit]

SPOJ_FCTRL

UVa_10139 - NB! int could overflow. See alternative implementation

UVa_160