Rowdark是一个邪恶的魔法师。在他阅读大巫术师Lich的传记时,他发现一类黑魔法来召唤远古生物,鱼丸。
魔法n能召唤类型i鱼丸当且仅当i能够被表示为x xor n*x对于某个正整数x和固定的n。
Rowdark想知道类型为[L,R]之间的鱼丸有多少种能被魔法n召唤。
输入第一行包含个整数n(1 ≤ n ≤ 107)。
第二行包含两个整数,L, R(0 ≤ L ≤ R ≤ 107)。
一行一个整数表示答案。
只有3(1 xor 2), 5(3 xor 6), 6(2 xor 4), 9(7 xor 14), 10(6 xor 12)满足要求。
2 1 10
5
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 10000000 + 10
int n, L, R;
bool vis[maxn];
int main()
{
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(~scanf("%d%d%d", &n, &L, &R))
{
int ans = 0;
memset(vis, 0, sizeof(vis));
for(int i=1; i<=10000000; i++)
{
long long j = (long long)i*n;
long long tmp = i^j;
if(tmp <= R)
vis[tmp] = true;
}
for(int i=L; i<=R; i++)
if(vis[i]) ans++;
printf("%d\n", ans);
}
return 0;
}
原文地址:http://blog.csdn.net/dojintian/article/details/46562445