Advertisement
Farjana_akter

Untitled

May 18th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. #define mx 1e12
  5. vector<ll>lucky,verylucky;
  6. ll len=0;
  7. map<ll,bool>flag;
  8. void generatelucky(ll n)
  9. {
  10. if(n>mx)
  11. return;
  12. if(n>0)
  13. {
  14. lucky.push_back(n);
  15. flag[n]=true;
  16. }
  17. generatelucky(10*n+4);
  18. generatelucky(10*n+7);
  19. }
  20.  
  21. void generateverylucky(ll n,ll index,ll len)
  22. {
  23. if(index>=len)
  24. return;
  25. for(ll i=index; i<len; i++)
  26. {
  27. ll x=n*lucky[i];
  28. if(x>mx || x<=0)
  29. return;
  30. verylucky.push_back(x);
  31. generateverylucky(x,i,len);
  32. }
  33.  
  34. }
  35.  
  36. int main()
  37. {
  38. generatelucky(0);
  39. sort(lucky.begin(),lucky.end());
  40. len=lucky.size();
  41. generateverylucky(1,0,len);
  42. for(ll i=0; i<len; i++)
  43. verylucky.push_back(lucky[i]);
  44. sort(verylucky.begin(),verylucky.end());
  45. verylucky.erase(unique(verylucky.begin(),verylucky.end()),verylucky.end());
  46. ll t,cas,i,a,b,low,high;
  47. cin>>t;
  48. for(cas=1; cas<=t; cas++)
  49. {
  50. cin>>a>>b;
  51. low=lower_bound(verylucky.begin(),verylucky.end(),a)-verylucky.begin();
  52. high=upper_bound(verylucky.begin(),verylucky.end(),b)-verylucky.begin();
  53. cout<<"Case "<<cas<<": "<<high-low<<endl;
  54. }
  55.  
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement