Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. /// Typedef
  6. typedef long long ll;
  7.  
  8. #define sc1(a) scanf("%lld",&a)
  9. #define sc2(a,b) scanf("%lld %lld",&a,&b)
  10.  
  11. #define pf1(a) printf("%lld\n", a)
  12. #define pf2(a,b) printf("%lld %lld\n",a,b)
  13.  
  14. #define mx 1000001
  15. #define mod 1000003
  16. #define PI acos(-1.0)
  17.  
  18. #define size1 1000003
  19.  
  20. int drx[8] = {-2,-2,-1,-1,1,1,2,2};
  21. int dcy[8] = {-1,1,-2,2,-2,2,-1,1};
  22.  
  23. int dirx[4] = { -1, 0, 1, 0 };
  24. int diry[4] = { 0, -1, 0, 1 };
  25.  
  26. ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b, a % b); }
  27. ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
  28.  
  29. ll InverseMod(ll base, ll pow)
  30. {
  31. if(pow == 0) return 1;
  32.  
  33. ll ans = InverseMod(base, pow / 2);
  34.  
  35. ans = (ans * ans) % mod;
  36.  
  37. if(pow & 1){
  38. return (ans * base) % mod;
  39. }
  40. else{
  41. return ans;
  42. }
  43. }
  44.  
  45. ll fecto[mx];
  46. void preFectorial()
  47. {
  48. fecto[1] = 1;
  49.  
  50. for(ll i = 2; i < mx; i++)
  51. fecto[i] = (fecto[i - 1] * i) % mod;
  52. }
  53.  
  54. int main() {
  55.  
  56. //seive();
  57.  
  58. preFectorial();
  59.  
  60. ll tc, num, t = 1, choose;
  61.  
  62. //freopen("/opt/Coding/clion code/input.txt", "r", stdin);
  63. //freopen("/opt/Coding/clion code/output.txt", "w", stdout);
  64.  
  65. sc1(tc);
  66.  
  67. while (tc--){
  68. ll choose;
  69.  
  70. sc2(num, choose);
  71.  
  72. cout << "Case " << t++ << ": ";
  73.  
  74. if(num < choose){
  75. cout << "0" << endl;
  76. continue;
  77. }
  78. if(num == choose || choose == 0){
  79. cout << "1" << endl;
  80. continue;
  81. }
  82.  
  83. ll upFect = fecto[num];
  84. ll downFect = ((fecto[num - choose] % mod) * (fecto[choose] % mod)) % mod;
  85.  
  86. ll ans = ((upFect % mod) * InverseMod(downFect, mod - 2)) % mod;
  87.  
  88. pf1(ans);
  89. }
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement