fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. long long Binomial(int n, int k)
  6. {
  7. double wynik = 1;
  8. for (int i = 1; i <= k; i++)
  9. wynik = wynik * (n-i+1)/i;
  10. return wynik;
  11. }
  12.  
  13. int main()
  14. {
  15. int n, k;
  16. long long expected;
  17. while (cin >> n >> k >> expected)
  18. {
  19. long long result = Binomial(n, k);
  20. cout << "(" << n << ", " << k << ") ";
  21. if (result == expected)
  22. cout << "OK" << endl;
  23. else
  24. cout << "failed!\nexpected: " << expected << "\n actual: " << result << endl;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 3460KB
stdin
1000 3 166167000
52 10 15820024220
30 15 155117520
33 16 1166803110
1000 998 499500
1000 2 499500

stdout
(1000, 3) OK
(52, 10) OK
(30, 15) OK
(33, 16) OK
(1000, 998) OK
(1000, 2) OK