Language: C++

#include <bits/stdc++.h>

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back
#define int ll

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 100, inf = 1000111222;

string tostr(ll a) {
    string s;
    while (a) {
        s += '0' + (a % 2);
        a /= 2;
    }
    return s;
}

ll dp[100];
ll dpt[100];
ll dpf[100];
ll p3[max_n];

ll solve(ll from, ll to) {
    //cout << from << ' '<< to << endl;
    string f = tostr(from), t = tostr(to);
    //cout << f << endl;
    //cout << t << endl;

    if (f.size() != t.size()) {
        exit(228);
    }
    if (f.back() != '1' || t.back() != '1') {
        exit(228);
    }
    memset(dp, 0, sizeof(dp));
    memset(dpf, 0, sizeof(dpf));
    memset(dpt, 0, sizeof(dpt));
    for (int i = 0; i < f.size(); ++i) {
        if (f[i] == '1') {
            if (i == 0) {
                dpf[i] = 1;
            } else {
                dpf[i] = dpf[i - 1];
            }
        } else {
            if (i == 0) {
                dpf[i] = 3;
            } else {
                dpf[i] = 2 * dpf[i - 1];
                dpf[i] += p3[i];
            }
        }
    }
    for (int i = 0; i < t.size(); ++i) {
        if (t[i] == '0') {
            if (i == 0) {
                dpt[i] = 1;
            } else {
                dpt[i] = dpt[i - 1];
            }
        } else {
            if (i == 0) {
                dpt[i] = 3;
            } else {
                dpt[i] = 2 * dpt[i - 1];
                dpt[i] += p3[i];
            }
        }
    }

    for (int i = 0; i < f.size(); ++i) {
        if (f[i] == '1' && t[i] == '0') {
            dp[i] = 0;
        }
        if (f[i] == '0' && t[i] == '1') {
            if (i == 0) {
                dp[i] = 3;
            } else {
                dp[i] = dpt[i - 1] + dpf[i - 1] + dp[i - 1];
            }
        }
        if (f[i] == '1' && t[i] == '1') {
            if (i == 0) {
                dp[i] = 1;
            } else {
                dp[i] = dp[i - 1];
            }
        }
        if (f[i] == '0' && t[i] == '0') {
            if (i == 0) {
                dp[i] = 1;
            } else {
                dp[i] = dp[i - 1];
            }
        }
    }
    //cout << "$ " << dp[0] << ' ' << dpt[0] << ' ' << dpf[0] << endl;
    return dp[f.size() - 1];
}

int dumb(int l, int r) {
    int ans =0;
    for (int i = l; i <= r; ++i) {
        for (int j = i; j <= r; ++j) {
            if (j % i == (j ^ i)) {
                ++ans;
            }
        }
    }
    return ans;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    ll l, r;
    cin >> l >> r;
    p3[0] = 1;
    for (int i = 1; i < 100; ++i) {
        p3[i] = 3 * p3[i - 1];
    }
    vector<pair<ll, ll>> ft, nd;
    ll from = 1;
    while(true) {
        ft.emplace_back(from, from * 2 - 1);
        from *= 2;
        if (from > 1e18) {
            break;
        }
    }
    for (pair<ll, ll> p : ft) {
        if (l > p.S || r < p.F) {
            continue;
        }
        nd.emplace_back(max(l, p.F), min(r, p.S));
    }
    ll ans = 0;
    //cout << solve(l, r) << ' ' << dumb(l, r) << endl;
    //exit(0);
    for (pair<ll, ll> p : nd) {
        ans += solve(p.F, p.S);
        //cout << "F " << solve(p.F, p.S) << ' ' << dumb(p.F, p.S) << endl;
    }
    cout << ans << endl;
    return 0;
}




Compiler output:
a.cc:8:13: error: '::main' must return 'int'
    8 | #define int ll
      |             ^~
a.cc:120:1: note: in expansion of macro 'int'
  120 | int main()
      | ^~~