Advertisement
niksan878

Problem 7.Calculate N! / (K! * (N-K)!)

Mar 26th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. class numberOfCombinations
  5. {
  6. static void Main()
  7. {
  8. BigInteger n = BigInteger.Parse(Console.ReadLine());
  9. BigInteger k = long.Parse(Console.ReadLine());
  10.  
  11. BigInteger nFactoriel = 1;
  12. BigInteger kFactoriel = 1;
  13. BigInteger nkFactoriel = 1;
  14. if (n > 1 && n < 100 && k > 1 && k < 100 && k < n)
  15. {
  16. for (int i = 0; i < n; i++)
  17. {
  18. nFactoriel *= n - i;
  19. if (k-i > 0)
  20. {
  21. kFactoriel *= k - i;
  22. }
  23. if (n-k-i > 0)
  24. {
  25. nkFactoriel *= (n - k) - i;
  26. }
  27. }
  28. }
  29. Console.WriteLine(nFactoriel / (kFactoriel * nkFactoriel));
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement