Saleh127

Light OJ 1102

Sep 15th, 2021
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5. ll mod=1e9+7;
  6. ll bigmod(ll a,ll c,ll d)
  7. {
  8. if(c==0) return 1LL;
  9. ll x=bigmod(a,c/2,d);
  10. x=(x*x)%d;
  11. if(c%2==1LL)
  12. {
  13. x=(x*a)%d;
  14. }
  15. return x;
  16. }
  17.  
  18. ll f[2000005];
  19. ll invf[2000005];
  20.  
  21. void fact()
  22. {
  23. ll i,j,k;
  24.  
  25. f[0]=1;
  26. for(i=1;i<=2000001;i++)
  27. {
  28. f[i]=(f[i-1]*i)%mod;
  29. ///invf[i]=bigmod(f[i],mod-2,mod);
  30. ///using inverse modulo for every number will give tle
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. ios_base::sync_with_stdio(0);
  37. cin.tie(0);cout.tie(0);
  38.  
  39. fact();
  40.  
  41.  
  42. test
  43. {
  44. ll n,m,i,j,k,l,ans;
  45.  
  46. cin>>n>>k;
  47.  
  48. ///stars and bars for 4 && 3;
  49. ///4 stars 3 bars;
  50. ///total will be 3-1 bars make 3 part
  51. /// so n+k-1 C k-1
  52.  
  53. ///ans=(f[n+k-1])%mod * invf[n]%mod * invf[k-1]%mod;
  54.  
  55. ans=f[n+k-1];
  56.  
  57. l=(f[n]*f[k-1])%mod;
  58.  
  59. l=bigmod(l,mod-2,mod);
  60.  
  61. ans=(ans*l)%mod;
  62.  
  63. cout<<"Case "<<cs<<": "<<ans<<endl;
  64. }
  65.  
  66. return 0;
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment