Advertisement
Saleh127

LO 1276

Oct 10th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll limit=1e12;
  6. vector<ll>lucky;
  7. map<ll,bool>visit;
  8. void cal()
  9. {
  10. lucky.push_back(4);
  11. lucky.push_back(7);
  12.  
  13. ll i=0,j;
  14.  
  15. visit[4]=1;
  16. visit[7]=1;
  17.  
  18. while(lucky[i]<=limit)
  19. {
  20. lucky.push_back((lucky[i]*10+4));
  21. visit[(lucky[i]*10+4)]=1;
  22. lucky.push_back((lucky[i]*10+7));
  23. visit[(lucky[i]*10+7)]=1;
  24. i++;
  25. }
  26.  
  27. sort(lucky.begin(),lucky.end());
  28.  
  29. for(i=0;i<lucky.size();i++)
  30. {
  31. for(j=0;j<lucky.size();j++)
  32. {
  33. if(lucky[i]*lucky[j]>limit)
  34. {
  35. break;
  36. }
  37. if(visit[(lucky[i]*lucky[j])]!=1)
  38. {
  39. visit[(lucky[i]*lucky[j])]=1;
  40. lucky.push_back((lucky[i]*lucky[j]));
  41. }
  42. }
  43. }
  44.  
  45. sort(lucky.begin(),lucky.end());
  46. }
  47.  
  48.  
  49.  
  50. int main()
  51. {
  52. ios_base::sync_with_stdio(0);
  53. cin.tie(0);cout.tie(0);
  54.  
  55. cal();
  56.  
  57. ll a,c,i,j,k;
  58.  
  59. test
  60. {
  61. cin>>a>>c;
  62. cout<<"Case "<<cs<<": ";
  63. k=upper_bound(lucky.begin(),lucky.end(),c)-lower_bound(lucky.begin(),lucky.end(),a);
  64. cout<<k<<endl;
  65.  
  66. }
  67. return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement