MAGCARI

Choose Bunz

Jul 8th, 2022
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. /*
  2.     Task        : Choose Bunz
  3.     Author      : Phumipat C. [MAGCARI]
  4.     Language    : C++
  5. */
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. int pascal[2][10010];
  9. int main(){
  10.     int n,r,k;
  11.     scanf("%d %d %d",&n,&r,&k);
  12.     for(int i=1;i<=n;i++){
  13.         pascal[i%2][0] = pascal[i%2][i] = 1%k;
  14.         for(int j=1;j<i;j++){
  15.             pascal[i%2][j] = (pascal[(i+1)%2][j-1] + pascal[(i+1)%2][j])%k;
  16.         }
  17.     }
  18.     printf("%d\n",pascal[n%2][r]%k);
  19.     return 0;
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment