Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef unsigned long long int ull;
- typedef long long int ll;
- typedef vector<int> vi;
- typedef vector<ll> vll;
- typedef vector<vi> vvi;
- typedef pair<int,int > pii;
- typedef vector< pii > vpii;
- typedef set<int> sti;
- #define sc scanf
- #define pf printf
- #define sci(n) scanf("%d",&n)
- #define scii(n,m) scanf("%d %d",&n,&m)
- #define scl(n) scanf("%lld",&n)
- #define scd(n) scanf("%lf",&n)
- #define scs(s) scanf("%s",s)
- #define pfi(n) printf("%d",n)
- #define pfl(n) printf("%lld",n)
- #define pff(n) cout<<n
- #define line printf("\n")
- #define spc printf(" ")
- #define clr(a,x) memset(a,x,sizeof(a))
- #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
- #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
- #define cspf(i) printf("Case %d: ", i)
- #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
- #define pb push_back
- #define mp make_pair
- #define ff first
- #define ss second
- #define all(v) v.begin(),v.end()
- #define rall(v) v.rbegin(),v.rend()
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
- /// Constants
- #define eps 1e-9
- #define PI acos(-1.0) // 3.1415926535897932
- #define MAX (ll)1e12
- #define Max (int)1e9
- ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b , a % b); }
- ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
- vll store;
- int sz;
- int lower(int lo,int hi,ll key)
- {
- if(lo>hi) return Max;
- int mid = (lo+hi)/2;
- if(store[mid]>=key) return min(mid,lower(lo, mid-1,key));
- return lower(mid+1,hi,key);
- }
- int upper(int lo,int hi,ll key)
- {
- if(lo>hi) return -Max;
- int mid = (lo+hi)/2;
- if(store[mid]<=key) return max(mid,upper(mid+1, hi,key));
- return upper(lo,mid-1,key);
- }
- void BT(ll n)
- {
- if(n>MAX) return;
- if(n) store.pb(n);
- BT(n*10+4);
- BT(n*10+7);
- }
- void products(int pos,ll n)
- {
- for(int i=pos;i<sz;i++){
- if(store[i]<=MAX/n){
- if(n!=1) store.pb(store[i]*n);
- products(i,store[i]*n);
- }
- else return;
- }
- }
- void generate()
- {
- BT(0);
- sort(all(store));
- sz=store.size();
- products(0,1);
- sort(all(store));
- store.erase(unique(all(store)),store.end());
- }
- int main()
- {
- generate();
- sz=store.size()-1;
- int t;
- sci(t);
- loop(ca,1,t){
- ll x,y;
- scl(x);scl(y);
- ll d = upper(0,sz,y)-lower(0,sz,x) + 1;
- if(d<0) d=0;
- cspf(ca);pfl(d);
- line;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement