显示原始代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fir first
#define sec second
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int ans = 0;
for (int i = 2; i < n; i += 2) {
int k = log2(i);
int d = (1 << (k + 1)) - i;
for (int j = 1; j * j <= i; j++) {
if (i % j == 0) {
int t1 = j, t2 = i / j;
if (i + t1 <= n && t1 < d) {
if (gcd(i, i + t1) == (i ^ (i + t1))) {
ans++;
}
}
if (i + t2 <= n && t2 < d && t1 != t2) {
if (gcd(i, i + t2) == (i ^ (i + t2))) {
ans++;
}
}
}
}
}
cout << ans << endl;
return 0;
}