Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CalculateNKNK
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int k = int.Parse(Console.ReadLine());
- int nSubK = n - k;
- ulong factN = GetFactorialN(n);
- ulong factK = GetFactorialK(k);
- ulong factNSubK = GetFactorialNSubK(nSubK);
- if (1 < k && k < n && n < 100)
- {
- ulong result = 1;
- result = factN / (factK * factNSubK);
- Console.WriteLine(result);
- }
- }
- private static ulong GetFactorialN(int n)
- {
- if (n == 0)
- {
- return 1;
- }
- return (ulong)n * GetFactorialN(n - 1);
- }
- private static ulong GetFactorialK(int k)
- {
- if (k == 0)
- {
- return 1;
- }
- return (ulong)k * GetFactorialK(k - 1);
- }
- private static ulong GetFactorialNSubK(int nSubK)
- {
- if (nSubK == 0)
- {
- return 1;
- }
- return (ulong)nSubK * GetFactorialNSubK(nSubK - 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement