time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility.

Initially Sam has a list with a single element n. Then he has to perform certain operations on this list. In each operation Sam must remove any element x, such that x > 1, from the list and insert at the same position  sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.

Now the masters want the total number of 1s in the range l to r (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test?

Input

The first line contains three integers nlr (0 ≤ n < 250, 0 ≤ r - l ≤ 105, r ≥ 1, l ≥ 1) – initial element and the range l to r.

It is guaranteed that r is not greater than the length of the final list.

Output

Output the total number of 1s in the range l to r in the final sequence.

Examples
input
7 2 5
output
4
input
10 3 10
output
5
Note

Consider first example:

这个题目做的挺漂亮嘛!哈哈!

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iostream>
#define MAXN 200009
#define eps 1e-11 + 1e-12/2
typedef long long LL; using namespace std;
/*
显然!分治!
*/
LL n, l ,r;
LL solve(LL x, LL beg,LL end)
{
LL mid = (beg + end) / ;
if (beg == mid) return ;
if (r < mid)
return solve(x / , beg, mid - );
else if (l > mid)
return solve(x / , mid + , end);
else
{
LL ret = x % ;
if (l < mid) ret += solve(x / , beg, mid - );
if (r > mid) ret += solve(x / , mid + , end);
return ret;
}
return ;
}
int main()
{ cin >> n >> l >> r;
if (n == )
{
cout << << endl;
return ;
}
LL len = pow(, floor(log2(n)) + ) - ;
cout << solve(n, , len) << endl;
}

最新文章

  1. .Net 转战 Android 4.4 日常笔记(5)--新软件Android Studio 0.5.8安装与配置及问题解决
  2. AppBox升级进行时 - Any与All的用法(Entity Framework)
  3. 关于oracle中日期使用
  4. 如何在启用SharePoint浏览器功能的InfoPath 表单中添加托管代码以动态地加载并显示图片
  5. zoj Treasure Hunt IV
  6. iphone获取当前磁盘信息
  7. Android MemInfo
  8. 自制node.js + npm绿色版
  9. NAND闪存供过于求的情况今年会有所好转吗?
  10. Gson学习文档
  11. 【GIS】Mapbox-json配置
  12. Asp.Net WebApi核心对象解析(一)
  13. 信息安全-加密:RAS 加密
  14. POSTGRESQL 锁表的问题
  15. kafka demo
  16. 使用Topshelf 5步创建Windows 服务
  17. testng参数化(提供测试数据)
  18. Python数学运算入门把Python当作计算器
  19. 最新eclipse安装SVN插件
  20. RGB和HSL色彩的相互转换

热门文章

  1. $CF241D\ Numbers$
  2. T - Posterized(贪心思维)
  3. linux centos7 安装nginx并启动
  4. js数组的各种方法
  5. (1)HTML声明与基础(已入垃圾筐)
  6. Java反射机制实战——字段篇
  7. C++(存储类)经典!!
  8. mongo 3.4分片集群系列之七:配置数据库管理
  9. 【PostgreSQL-9.6.3】LOG: unrecognized configuration parameter &quot;dynamic_shared_memory_type&quot;
  10. windows系统下的redis启动教程