fork(4) download
  1. #include<bits/stdc++.h>
  2. #include <vector>
  3. #include <ctime>
  4. #define ll long long
  5. #define mod 1000000007
  6. using namespace std;
  7. ll fact[100011],invfact[100011];
  8.  
  9. ll pow(ll a, ll b)
  10. {
  11. ll x=1,y=a;
  12. while(b > 0)
  13. {
  14. if(b%2 == 1)
  15. {
  16. x=(x*y);
  17. if(x>mod) x%=mod;
  18. }
  19. y = (y*y);
  20. if(y>mod) y%=mod;
  21. b /= 2;
  22. }
  23. return x;
  24. }
  25. void preprocess()
  26. {
  27. fact[0]=fact[1]=1;
  28. invfact[0]=invfact[1]=-1;
  29. for(int i=2;i<100001;i++)
  30. {
  31. fact[i]=(fact[i-1]*i);
  32. fact[i]%=mod;
  33. invfact[i]=-1;
  34. }
  35.  
  36. }
  37. ll comb(ll n, ll k)
  38. {
  39. if(invfact[k]==-1)
  40. {
  41. invfact[k]=pow(fact[k],mod-2);
  42. invfact[k]%=mod;
  43. }
  44. if(invfact[n-k]==-1)
  45. {
  46. invfact[n-k]=pow(fact[n-k],mod-2);
  47. invfact[n-k]%=mod;
  48. }
  49. return ( ( ( fact[n] * invfact[k] ) % mod ) * invfact[n-k] ) % mod;
  50. }
  51. int main()
  52. {
  53. preprocess();
  54. cout<<comb(10,2);
  55. }
  56.  
Success #stdin #stdout 0s 4972KB
stdin
Standard input is empty
stdout
399918626