/ 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
Expand |
Embed | Plain Text
/// <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; }
You need to login to post a comment.
