提交时间:2024-08-20 16:12:32

运行 ID: 169271

#include <iostream> #include <bits/stdc++.h> using namespace std; long long countBinaryNumbers(int n, long long s, long long t) { auto countOnes = [](long long num) { int count = 0; while (num > 0) { if (num % 2 == 1) { count++; } num /= 2; } return count; }; int numOnesS = countOnes(s); int numOnesT = countOnes(t); long long count = 0; for (int i = numOnesS; i <= numOnesT; i++) { long long comb = 1; for (int j = 1; j <= i; j++) { comb = comb * (n - j + 1) / j; } count += comb; } return count; } int main() { int n; long long s, t; cin >> n >> s >> t; long long result = countBinaryNumbers(n, s, t); cout << result << endl; return 0; }