/ Published in: C#
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
Ex: 5! = (2^3)*(3^1)*(5^1)
mult(5,2) = 3
mult(5,3) = 1
mult(5,5) = 1
all else = 0
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/// <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; }