帮忙检查一下我的代码吧!
我正在做GESP5级的有趣的数字和,这是2025年9月的题目。可是我的代码老是出bug,我用平台的是洛谷(luogu)。你们可不可以看看为什么?(屑Bro已经快崩了
)我的代码:
#include<bits/stdc++.h>
using namespace std;
int a[24], l, r, sum;
bool check(int x){
int x2 = x, cnt = 0;
while(x2 > 0){
cnt += x2 % 2;
x2 /= 2;
}
return cnt % 2 == 1;
}
int main(){
for(int i = 0; i < 6; i++){
for(int j = 0; j < 24; j++){
if(check(i * 24 + j)){
a[i * 24 + j] = 1;
}
}
}
cin >> l;
cin >> r;
for(int i = l; i <= r; i++){
if(a[i % 24]) sum += i;
}
cout << sum;
return 0;
}
我的思路:
我发现满足“有趣”这个概念的数是有循环的。而check函数可以检测这个条件,所以我想按照循环来进行
具体症状:
部分答案错误,部分情况超时。
请各位大佬帮帮我!







