Advertisement
Guest User

Calculate 3

a guest
Sep 5th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Calculate_3
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int n = int.Parse(Console.ReadLine());
  15.             int k = int.Parse(Console.ReadLine());
  16.             //опитвам да раздробя формулата и да пресметна отделните ѝ части.
  17.             BigInteger resultNFac = 1;
  18.             BigInteger resultKFac = 1;
  19.             BigInteger result = 0;
  20.             BigInteger nMinusKFac = 1;
  21.             if (1<k&&k<n&&n<100)    
  22.             {
  23.                 for (int i = 1; i <= n; i++)
  24.                 {
  25.                     //N! / (K! * (N - K)!)
  26.                     resultNFac *= i;
  27.                    
  28.                     if (i==k)
  29.                     {
  30.                         resultKFac = resultNFac;
  31.                         int nMinusK = n - k;
  32.                         for (int y = 1; y <= nMinusK; y++)
  33.                         {
  34.                             nMinusKFac *= y;
  35.                         }
  36.  
  37.                     }
  38.                 }
  39.                 result = resultNFac / (resultKFac * nMinusKFac);
  40.                 Console.WriteLine(result);
  41.                 //Входни данни: 3 and 2 with result 3; 4 and 2 with res 6; 52 and 5 with res 2598960;
  42.                 //При въвеждане на посочения input програмата връща правилния отговор, но в judge системата има грешка при тест 10.
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement