Posted By

FMalk on 08/30/11


Tagged

number prime factorial factoring factorization


Versions (?)

Factorial prime numbers factorization


 / 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

  1. /// <summary>
  2. /// Find how many factors there is in N for a prime P
  3. /// </summary>
  4. static int multiplicity(int n, int p)
  5. {
  6. int q = n, m = 0;
  7. if (p > n) return 0;
  8. if (p > n / 2) return 1;
  9. while (q >= p)
  10. {
  11. q /= p;
  12. m += q;
  13. }
  14. return m;
  15. }

Report this snippet  

You need to login to post a comment.