lina_os

Untitled

Jun 13th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define ul unsigned long long
  5. #define ld long double
  6. #define vll(v) vector<ll>v
  7. //#define vll(v,n) vector<ll>v(n);
  8. #define mll(m) map<ll,ll>m;
  9. #define sll(s) set<ll>s;
  10. #define iv(v) for(auto &i:v) cin >> i;
  11. #define ov(v) for(auto &i:v) cout << i << " ";
  12. #define Bismillah ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  13.  
  14. using namespace std;
  15.  
  16. void solve() {
  17.     ll a,b;
  18.     cin >> a >> b;
  19.     string aa,bb;
  20.  
  21.     while (a) {
  22.         if (a%2) aa.push_back('1');
  23.         else aa.push_back('0');
  24.         a/=2;
  25.     }
  26.     while (b) {
  27.         if (b%2) bb.push_back('1');
  28.         else bb.push_back('0');
  29.         b/=2;
  30.     }
  31.     while (aa.back()=='0') aa.pop_back();
  32.     while (aa.back()=='0') aa.pop_back();
  33.     reverse(aa.begin(), aa.end());
  34.     reverse(bb.begin(), bb.end());
  35.     ll ans=0;
  36.     for (int i=0; i<aa.size(); i++) {
  37.         if (aa[i]=='0') {
  38.             for (int j=i+1; j<aa.size(); j++) {
  39.                 aa[j]='1';
  40.             }
  41.             while (true) {
  42.                 if (aa.size()<bb.size() || aa.size()==bb.size() && aa<=bb) ans++;
  43.                 for (int l=i+1; l<aa.size(); l++) {
  44.                     aa[l-1]='1';
  45.                     aa[l]='0';
  46.                     if (aa.size()<bb.size() || aa.size()==bb.size() && aa<=bb) ans++;
  47.                     else {
  48.                         cout << ans << endl;
  49.                         return;
  50.                     }
  51.                 }
  52.                 aa.back()='1';
  53.                 aa.push_back('1');
  54.                 aa[1]='0';
  55.                 i=0;
  56.             }
  57.         }
  58.     }
  59. }
  60.  
  61. int main() {
  62.     Bismillah
  63.     ll t=1;
  64. //    cin >> t;
  65.     while (t--) {
  66.         solve();
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment