You are viewing a single comment's thread. Return to all comments →
My simple approach
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define leadinz zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1)); using namespace __gnu_pbds; using namespace std; typedef unsigned long long ll; int len(unsigned long long n) { string s=to_string(n); return s.size(); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); queue<ll> q; vector<ll>ans; int T; ans.push_back(0); for (int i=1;i<10;i++) q.push(i); while(!q.empty()){ ll x = q.front(); q.pop(); ans.push_back(x); for (int i=len(x);i<=18;i++) if (i-1 && len(x * i) == i) q.push(x * i); } sort(ans.begin(),ans.end()); cin >> T; while(T--){ ll L,R; cin >> L >> R; int x = count_if(ans.begin(),ans.end(),[L](ll i){return i<L;}); int y = count_if(ans.begin(),ans.end(),[R](ll i){return i<=R;}); if(x!=0)cout << y-x<<endl; else cout<<y<<endl; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Strange numbers
You are viewing a single comment's thread. Return to all comments →
My simple approach