Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- #define mx 1e12
- vector<ll>lucky,verylucky;
- ll len=0;
- map<ll,bool>flag;
- void generatelucky(ll n)
- {
- if(n>mx)
- return;
- if(n>0)
- {
- lucky.push_back(n);
- flag[n]=true;
- }
- generatelucky(10*n+4);
- generatelucky(10*n+7);
- }
- void generateverylucky(ll n,ll index,ll len)
- {
- if(index>=len)
- return;
- for(ll i=index; i<len; i++)
- {
- ll x=n*lucky[i];
- if(x>mx || x<=0)
- return;
- verylucky.push_back(x);
- generateverylucky(x,i,len);
- }
- }
- int main()
- {
- generatelucky(0);
- sort(lucky.begin(),lucky.end());
- len=lucky.size();
- generateverylucky(1,0,len);
- for(ll i=0; i<len; i++)
- verylucky.push_back(lucky[i]);
- sort(verylucky.begin(),verylucky.end());
- verylucky.erase(unique(verylucky.begin(),verylucky.end()),verylucky.end());
- ll t,cas,i,a,b,low,high;
- cin>>t;
- for(cas=1; cas<=t; cas++)
- {
- cin>>a>>b;
- low=lower_bound(verylucky.begin(),verylucky.end(),a)-verylucky.begin();
- high=upper_bound(verylucky.begin(),verylucky.end(),b)-verylucky.begin();
- cout<<"Case "<<cas<<": "<<high-low<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement