提交时间:2024-08-20 16:44:10
运行 ID: 169719
#include <bits/stdc++.h> using namespace std; const int N = 50; int a[N]; int n, s, t; int f[51][51]; int c(int num){ int len; for(len = 0; num > 0; num /= 2) a[len++] = num % 2; long long ans = 0; for(int i = 0, cnt = 0; i < len && cnt < n; i++){ if(a[len - i - 1] == 1){ ans += f[len - i - 1][n - cnt]; cnt++; } } return ans; } int main(){ cin >> n >> s >> t; for(int i = 0; i < N; i++) f[i][0] = f[0][i] = 1; for(int i = 1; i < N; i++){ for(int j = 1; j < N; j++){ f[i][j] = f[i - 1][j] + f[i - 1][j - 1]; } } cout << c(t) - c(s - 1); return 0; }