提交时间:2024-08-20 22:13:04
运行 ID: 173619
#include <iostream> using namespace std; int countOnes(int x) { int count = 0; while (x) { count += x & 1; x >>= 1; } return count; } int countNumbersWithOnes(int s, int t, int ones) { int count = 0; for (int i = s; i <= t; ++i) { if (countOnes(i) == ones) { count++; } } return count; } int main() { int n, s, t; cin >> n >> s >> t; int count = 0; for (int ones = 0; ones <= n; ++ones) { count += countNumbersWithOnes(s, t, ones); } cout << count << endl; return 0; }