Advertisement
Riz1Ahmed

nCr nPr

Feb 19th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <string.h>
  3. #define ll long long int
  4. ll fact[1000000],M=1e9+7;
  5. ll nCr(ll n,ll r){
  6.     if (n<r) return 0;
  7.     return fact[n]/(fact[r]*fact[n-r]);
  8. }
  9. ll nPr(ll n,ll r){
  10.     if (n<r) return 0;
  11.     return fact[n]/fact[n-r];
  12. }
  13. int main(){
  14.     ll n,r;
  15.     fact[0]=1;
  16.     for (int i=1;i<=100000;i++)
  17.         fact[i]=(fact[i-1]*i)%M;
  18.     while (~scanf("%lld %lld",&n,&r)){
  19.         printf("nCr=%lld, nPr=%lld\n",
  20.             nCr(n,r),nPr(n,r));
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement