Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ul unsigned long long
- #define ld long double
- #define vll(v) vector<ll>v
- //#define vll(v,n) vector<ll>v(n);
- #define mll(m) map<ll,ll>m;
- #define sll(s) set<ll>s;
- #define iv(v) for(auto &i:v) cin >> i;
- #define ov(v) for(auto &i:v) cout << i << " ";
- #define all(v) (v.begin(),v.end());
- #define Bismillah ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- using namespace std;
- string toBin(ll n) {
- string s;
- while (n) {
- s.push_back(n%2+'0');
- n/=2;
- }
- reverse(s.begin(), s.end());
- return s;
- }
- string toNice(ll n, ll i) {
- string s;
- while (n) {
- s.push_back((n%2)?'9':'6');
- n/=2;
- }
- while (s.size()<i) s.push_back('6');
- reverse(s.begin(), s.end());
- return s;
- }
- void solve() {
- ll l,r;
- cin >> l >> r;
- string sl=to_string(l);
- string sr=to_string(r);
- ll ans=0;
- for (ll i=sl.size()+1; i<sr.size(); i++) {
- ans+=1<<i;
- }
- ll i=sl.size();
- if (i<=18) {
- for (ll j = 0; j < (1 << i); j++) {
- string s = toNice(j,i);
- ll ss = stoll(s);
- if (ss >= l && ss <= r) ans++;
- else if (ss > r) break;
- }
- }
- if (sl.size()!=sr.size() && sr.size()<=18) {
- i=sr.size();
- for (ll j=0; j<(1<<i); j++) {
- string s=toNice(j,i);
- ll ss=stoll(s);
- if (ss>=l&&ss<=r) ans++;
- else if (ss>r) break;
- }
- }
- cout << ans << endl;
- }
- int main() {
- Bismillah
- // cout << (1<<18)*18*5 << endl;
- ll t=1;
- cin >> t;
- while (t--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment