fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fi first
  4. #define se second
  5.  
  6. typedef long long ll;
  7. typedef pair<int, int> pii;
  8.  
  9. template <class X, class Y> bool mini(X& x, const Y& y) {
  10. if(x > y){ x = y; return 1; }
  11. return 0;
  12. }
  13.  
  14. template <class X, class Y> bool maxi(X& x, const Y& y) {
  15. if(x < y){ x = y; return 1; }
  16. return 0;
  17. }
  18.  
  19. const short N = 105;
  20.  
  21. short n, q = 3;
  22. pii a[N], qe[5];
  23.  
  24. namespace sub1
  25. {
  26. bool check()
  27. {
  28. return n <= 25;
  29. }
  30.  
  31. const int SZ = 34e6;
  32.  
  33. ll MXR = 0;
  34. int cnt[5], div[SZ], cntd = 0;
  35. void dq(short pos, int cur)
  36. {
  37. if(pos > n){
  38. div[++cntd] = cur;
  39. return ;
  40. }
  41.  
  42. ll t = 1;
  43. for(int i = 0; i <= a[pos].se; ++i){
  44. if(cur * t > MXR) return ;
  45.  
  46. dq(pos + 1, cur * t);
  47. t *= a[pos].fi;
  48. }
  49. }
  50. void run()
  51. {
  52. for(int i = 1; i <= q; ++i)
  53. maxi(MXR, qe[i].se);
  54.  
  55. dq(1, 1);
  56. sort(div + 1, div + 1 + cntd);
  57.  
  58. for(int i = 1; i <= q; ++i){
  59. int l = qe[i].fi, r = qe[i].se;
  60. auto L = lower_bound(div + 1, div + 1 + cntd, l);
  61. auto R = upper_bound(div + 1, div + 1 + cntd, r);
  62. cout << R - L << "\n";
  63. }
  64. }
  65. }
  66.  
  67. namespace sub2
  68. {
  69. void run()
  70. {
  71.  
  72. }
  73. }
  74.  
  75. int main()
  76. {
  77. ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  78. #define file "UOCSO"
  79. if(fopen(file".inp", "r")){
  80. freopen(file".inp", "r", stdin);
  81. freopen(file".out", "w", stdout);
  82. }
  83.  
  84. cin >> n;
  85. for(int i = 1; i <= n; ++i){
  86. cin >> a[i].fi >> a[i].se;
  87. mini(a[i].se, 29);
  88. }
  89. for(int i = 1; i <= q; ++i){
  90. cin >> qe[i].fi >> qe[i].se;
  91. }
  92.  
  93. // sub2::run();
  94.  
  95. if(sub1::check()) sub1::run();
  96. else sub2::run();
  97.  
  98. return 0;
  99. }
  100.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
0
0
0