New Year and Old Property CodeForces - 611B
2017-09-20 09:36
549 查看
参考博客:http://blog.csdn.net/loy_184548/article/details/50864501
PS:网上还有说用dfs跑寻找唯一具有一个0的情况,(貌似是官方答案,是模拟+dfs的形式,….(有意向的同学可以自己查一下))
Input
Output
Example
Input
Note
题目内容:给你一个区间[a,b],求在[a,b]范围内的数的二进制编码只有一个零的情况。
我没有思路,参考博客的思路是求出二进制都为1的情况下的数字,在跑循环减掉一个0 ,-2^n方,每一次求出来的数必定符合题意,即可
PS:网上还有说用dfs跑寻找唯一具有一个0的情况,(貌似是官方答案,是模拟+dfs的形式,….(有意向的同学可以自己查一下))
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510 = 111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros.
Input
The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 1018) — the first year and the last year in Limak's interval respectively.
Output
Print one integer – the number of years Limak will count in his chosen interval.
Example
Input
5 10 Output 2 Input 2015 2015 Output 1 Input 100 105 Output 0 Input 72057594000000000 72057595000000000 Output 26
Note
In the first sample Limak's interval contains numbers 510 = 1012, 610 = 1102, 710 = 1112, 810 = 10002, 910 = 10012 and 1010 = 10102. Two of them (1012 and 1102) have the described property.
题目内容:给你一个区间[a,b],求在[a,b]范围内的数的二进制编码只有一个零的情况。
我没有思路,参考博客的思路是求出二进制都为1的情况下的数字,在跑循环减掉一个0 ,-2^n方,每一次求出来的数必定符合题意,即可
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll top[100]; inline void find_top() { int i; top[0]=1; for (i=1;i<=64;i++) { top[i]=top[i-1]+pow(2,i); } } int solve (ll &a,ll &b) { int i,j; int ans =0; for (i=0;i<64;i++) { ll temp=pow(2,i); for (j=i+1;j<64;j++) if (top[j]-temp>=a&&top[j]-temp<=b) ans++; } return ans; } int main () { find_top(); ll a, b; cin>>a>>b; cout<<solve(a,b)<<endl; return 0; }
相关文章推荐
- New Year and Old Property CodeForces - 611B
- Codeforences Goodbye 2015 B New Year and Old Property
- codeforces-611B-New Year and Old Property
- New Year and Rating CodeForces - 750C
- New Year and Curling CodeForces - 908C
- I - New Year and Rating CodeForces - 750C 模拟
- Codeforces GoodBye2015 New Year and Three Musketeers Codeforces 611E(贪心)
- New Year and North Pole CodeForces - 750B
- Codeforces GoodBye2015 New Year and Three Musketeers Codeforces 611E(贪心)
- B. New Year and Old Property
- 【Goodbye2015】Codeforces 611B New Year and Old Property【思维】
- C - New Year and Hurry CodeForces - 750A(动态规划)
- codeforces GoodBye2015 D.New Year and Ancient Prophecy (dp+lcp+树状数组)
- 【转】Codeforces GoodBye2015 New Year and Three Musketeers Codeforces 611E(贪心)
- New Year and Rating CodeForces - 750C
- E - New Year and North Pole CodeForces - 750B(状态处理下就好了)
- New Year and Rating CodeForces - 750C
- cf#gb2015-B - New Year and Old Property-暴力
- codeforces goodbye 2016 C. New Year and Rating
- E - New Year and Old Property