Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- class NumberOfCombinations
- {
- static void Main()
- {
- int N = int.Parse(Console.ReadLine());
- int K = int.Parse(Console.ReadLine());
- Combinations(N, K);
- Console.WriteLine(Combinations(N,K));
- }
- static BigInteger Combinations(int N, int K)
- {
- BigInteger factorialN = 1;
- BigInteger factorialK = 1;
- BigInteger factorialNK = 1;
- BigInteger resFactorials = 0;
- for (int i = 1; i <= N; i++)
- {
- factorialN = factorialN * i;
- if(i <= K)
- {
- factorialK = factorialK * i;
- }
- if(i <= N- K)
- {
- factorialNK = factorialNK * i;
- }
- }
- resFactorials = factorialK * factorialNK;
- return factorialN / resFactorials;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment