2
2025-08-15 15:34:36
发布于:浙江
3阅读
0回复
0点赞
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 998244353;
int count_pairs(int n, int k) {
int res = 0;
for (int x = 0; x <= n; ++x) {
for (int y = x + 1; y <= n; ++y) {
int diff = x ^ y;
int cnt = 0;
while (diff) {
cnt += diff & 1;
diff >>= 1;
}
if (cnt <= k) {
res = (res + 1) % MOD;
}
}
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
cout << count_pairs(n, k) << "\n";
}
return 0;
}
这里空空如也
有帮助,赞一个