thesonpb

tổ hợp chập k của n

Mar 30th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. long long int thc(int n, int k){
  4.     long long int sum1=1, sum2=1, sum3=1;
  5.     for(int i=1; i<=n; i++){
  6.         sum1*=i;
  7.     }
  8.     for(int i=1; i<=k; i++){
  9.         sum2*=i;
  10.     }
  11.     for(int i=1; i<=n-k; i++){
  12.         sum3*=i;
  13.     }
  14.     return sum1/(sum2*sum3);
  15. }
  16. int main(){
  17.     int m, n;
  18.     while(m!=-1 && n!=-1){
  19.         cin >> m>> n;
  20.         if(m!=-1 && n!=-1)
  21.         cout<<thc(m, n)<<endl;
  22.     }
  23. }
Add Comment
Please, Sign In to add comment