loulett

HW1_cnk

Oct 24th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. int main()
  4. {
  5.     int n = 0, k = 0, ans = 1;
  6.     scanf("%d", &n);
  7.     scanf("%d", &k);
  8.     if (k > n || k < 0 || n < 0)
  9.     {
  10.         printf("%d\n", ans - 1);
  11.     }
  12.     else
  13.     {
  14.         for (int i = k + 1; i <= n; ++i)
  15.         {
  16.             ans = ans * i / (i - k);
  17.         }
  18.         printf("%d\n", ans);
  19.     }
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment