Advertisement
erfanul007

LOJ 1276

Dec 9th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scii(n,m) scanf("%d %d",&n,&m)
  17. #define scl(n) scanf("%lld",&n)
  18. #define scd(n) scanf("%lf",&n)
  19. #define scs(s) scanf("%s",s)
  20. #define pfi(n) printf("%d",n)
  21. #define pfl(n) printf("%lld",n)
  22. #define pff(n) cout<<n
  23. #define line printf("\n")
  24. #define spc printf(" ")
  25. #define clr(a,x) memset(a,x,sizeof(a))
  26. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  27. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  28. #define cspf(i) printf("Case %d: ", i)
  29. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  30. #define pb push_back
  31. #define mp make_pair
  32. #define ff first
  33. #define ss second
  34. #define all(v) v.begin(),v.end()
  35. #define rall(v) v.rbegin(),v.rend()
  36. #define read() freopen("input.txt", "r", stdin)
  37. #define write() freopen("output.txt", "w", stdout)
  38. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  39. /// Constants
  40. #define eps 1e-9
  41. #define PI acos(-1.0) // 3.1415926535897932
  42. #define MAX (ll)1e12
  43. #define Max (int)1e9
  44.  
  45. ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b , a % b); }
  46. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  47.  
  48. vll store;
  49. int sz;
  50.  
  51. int lower(int lo,int hi,ll key)
  52. {
  53. if(lo>hi) return Max;
  54. int mid = (lo+hi)/2;
  55. if(store[mid]>=key) return min(mid,lower(lo, mid-1,key));
  56. return lower(mid+1,hi,key);
  57. }
  58.  
  59. int upper(int lo,int hi,ll key)
  60. {
  61. if(lo>hi) return -Max;
  62. int mid = (lo+hi)/2;
  63. if(store[mid]<=key) return max(mid,upper(mid+1, hi,key));
  64. return upper(lo,mid-1,key);
  65. }
  66.  
  67. void BT(ll n)
  68. {
  69. if(n>MAX) return;
  70. if(n) store.pb(n);
  71. BT(n*10+4);
  72. BT(n*10+7);
  73. }
  74.  
  75. void products(int pos,ll n)
  76. {
  77. for(int i=pos;i<sz;i++){
  78. if(store[i]<=MAX/n){
  79. if(n!=1) store.pb(store[i]*n);
  80. products(i,store[i]*n);
  81. }
  82. else return;
  83. }
  84. }
  85.  
  86. void generate()
  87. {
  88. BT(0);
  89. sort(all(store));
  90. sz=store.size();
  91. products(0,1);
  92. sort(all(store));
  93. store.erase(unique(all(store)),store.end());
  94. }
  95.  
  96. int main()
  97. {
  98. generate();
  99.  
  100. sz=store.size()-1;
  101. int t;
  102. sci(t);
  103. loop(ca,1,t){
  104. ll x,y;
  105. scl(x);scl(y);
  106. ll d = upper(0,sz,y)-lower(0,sz,x) + 1;
  107. if(d<0) d=0;
  108. cspf(ca);pfl(d);
  109. line;
  110. }
  111.  
  112. return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement