Advertisement
Falak_Ahmed_Shakib

ncr by mod

Jan 27th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5. typedef pair<ll,ll>pll;
  6. typedef pair<ll,pair<ll,ll>>plll;
  7. #define bismillah; (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  8. #define vll(v) v.begin(),v.end()
  9. #define all(x) x.rbegin(),x.rend()
  10. #define min3(a, b, c) min(a, min(b, c))
  11. #define max3(a, b, c) max(a, max(b, c))
  12. #define ff first
  13. #define ss second
  14. #define in freopen("input.txt", "r", stdin)
  15. #define out freopen("output.txt", "w", stdout)
  16. #define minheap int,vector<int>,greater<int>
  17. #define pb push_back
  18. #define eb emplace_back
  19. #define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
  20. #define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
  21. #define bug cout<<"BUG"<<endl;
  22. const int Max = 2e5 ;
  23. const int Mod = 1e9 + 7;
  24. ll fact[Max+10];
  25. long long bigmod(long long b,long long p,ll mod)
  26. {
  27.  
  28. if(p==0)return 1ll;
  29.  
  30. ll x=bigmod(b,p/2,mod);
  31.  
  32. x=(x*x)%mod;
  33.  
  34. if(p&1)x=(x*b)%mod;
  35.  
  36. return x;
  37. }
  38.  
  39.  
  40. void init()
  41. {
  42. fact[0]=1;
  43.  
  44. for(ll i=1; i<=Max; i++)
  45. {
  46. fact[i]=(i*fact[i-1])%Mod;
  47. }
  48. }
  49.  
  50. ll NCR(ll n,ll r)
  51. {
  52. return (fact[n]*bigmod((fact[r]*fact[n-r])%Mod,Mod-2,Mod))%Mod;
  53.  
  54. }
  55. int main()
  56. {
  57.  
  58. bismillah;
  59.  
  60.  
  61. cin>>nn>>rr;
  62.  
  63. ll ans=NCR(nn,rr);
  64.  
  65.  
  66. cout<<ans<<endl;
  67.  
  68.  
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement