不同的枚举方法,效率完全不同。值得记录一下!
#include <cstdio>
#include <cstring>
int t, a, b, c, n, cas = , count = ;
int cnt[];
void pre() {
count = ;
memset(cnt, , sizeof(cnt)); for (a = ; a <= ; a++) {
for (c = ; c < a; c++) {
if (a%c == && ((a-c)^a)==c) {
count++;
}
}
cnt[a-] = count;
} }
int main(void)
{ for (scanf("%d", &t); t--;) {
scanf("%d", &n);
printf("Case %d: %d\n", ++cas, cnt[n-]);
}
return ;
}
#include <cstdio>
#include <cstring>
int t, a, b, c, n, cas = , count = ;
const int maxn = ;
int cnt[maxn];
void pre() {
count = ;
memset(cnt, , sizeof(cnt)); for (c = ; c <= maxn/; c++) {
for (a = c+c; a <= maxn; a+=c) {
if (((a-c)^a)==c) {
cnt[a]++;
}
}
}
for (int i = ; i <= maxn; i++) {
cnt[i] += cnt[i-];
} }
int main(void)
{
pre();
for (scanf("%d", &t); t--;) {
scanf("%d", &n);
printf("Case %d: %d\n", ++cas, cnt[n]);
}
return ;
}