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 Bismillah ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- using namespace std;
- void solve() {
- ll a,b;
- cin >> a >> b;
- string aa,bb;
- while (a) {
- if (a%2) aa.push_back('1');
- else aa.push_back('0');
- a/=2;
- }
- while (b) {
- if (b%2) bb.push_back('1');
- else bb.push_back('0');
- b/=2;
- }
- while (aa.back()=='0') aa.pop_back();
- while (aa.back()=='0') aa.pop_back();
- reverse(aa.begin(), aa.end());
- reverse(bb.begin(), bb.end());
- ll ans=0;
- for (int i=0; i<aa.size(); i++) {
- if (aa[i]=='0') {
- for (int j=i+1; j<aa.size(); j++) {
- aa[j]='1';
- }
- while (true) {
- if (aa.size()<bb.size() || aa.size()==bb.size() && aa<=bb) ans++;
- for (int l=i+1; l<aa.size(); l++) {
- aa[l-1]='1';
- aa[l]='0';
- if (aa.size()<bb.size() || aa.size()==bb.size() && aa<=bb) ans++;
- else {
- cout << ans << endl;
- return;
- }
- }
- aa.back()='1';
- aa.push_back('1');
- aa[1]='0';
- i=0;
- }
- }
- }
- }
- int main() {
- Bismillah
- ll t=1;
- // cin >> t;
- while (t--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment