Hihocoder 计数
2015-06-19 15:59
183 查看
题目2 : 计数
时间限制:10000ms单点时限:1000ms
内存限制:256MB
描述
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; }
相关文章推荐
- FICO上线准备
- #include和#include“”的区别
- stm32.cube(七)——arm-gcc.helloworld
- 策略模式
- 在VBA中调用winsock控件
- oracle 表查询(2)
- LeetCode_44---Wildcard Matching
- Nginx反向代理 实现4台服务器负载均衡
- vs2012 error c4996: This function or variable may be unsafe
- MyBatis联合查询association使用
- this关键字
- 关于Android 和 JS 交互时调用不成功的问题
- C# WinForm捕获未处理的异常实例解析
- ios平台中glsl中shadow2DProjEXT函数的简单说明以及变换矩阵的小注意点
- IOS中WebView的使用
- android退出MainActivity后onDestroy不回调
- dede列表标签递增数字生成
- OC 九宫格布局
- 技术演绎之 [ java ] java标识符
- JS 新窗口打开超链接