Title Link: Http://codeforces.com/problemset/problem/611/B
The title means: in [A, b] this range (1≤ a ≤ b ≤10^)Statistics of the number of matching binary means that only 1 0 of the quantity is what.
***********************
First post a piece of code that will definitely time out, even the courage to submit the wood has it ~ because the fourth group of data is approaching the turtle speed, so ... (Everyone can ignore)
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5 using namespacestd;6 7 typedef __int64 LL;8 ll A, B;9 ll ans;Ten One intMain () A { - #ifndef Online_judge -Freopen ("In.txt","R", stdin); the #endif //Online_judge - - while(SCANF ("%i64d%i64d", &a, &b)! =EOF) { - __int64 i; +Ans =0; - + for(i = A; I <= B; i++) { A__int64 L =i; at intc =0; - while(l && C <=1) { -c + = ((L &1) ==0?1:0); -L >>=1; - } - if(c = =1) inans++; - to } +printf"%i64d\n", ans); - } the return 0; *}
***********************
Talk about the right way to solve the problem-that is, the violent enumeration .... Of course, not the decimal number first into a binary number and then slowly compared to, I above the code is similar to this thought, said many are tears, Woo Woo ~ ~ ~
is the analog binary number, in the [1, 10^18] range, the statistics show only binary representation of 0 occurrences 1 times
For the first time, I knew it was possible. = = 、、、 slowly accumulate experience ~ ~ ~
In addition to say a number of the range, 2^61 is already bigger than 10^18, so when enumerating, for example to 61 times on the line, the code has detailed comments, we slowly appreciate ^_^
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5 using namespacestd;6 7 typedef __int64 LL;8 Const intbit = A;//2^61 = 1,152,921,504,606,846,9769 Ten intMain () One { A #ifndef Online_judge -Freopen ("In.txt","R", stdin); - #endif //Online_judge the - ll A, B; - while(SCANF ("%i64d%i64d", &a, &b)! =EOF) { - intAns =0; + - for(inti =2; I <= bit; i++) { +ll mea = (1ll << i)-1;//1, one, 111, 1111, ... A at for(intj =0; J < i-1; J + +) { -ll t = mea-(1ll << J);//(1LL<<J): 1, ten , ... -Ans + = (t >= a && t <=b); - } - } -printf"%d\n", ans); in } - return 0; to}
Codeforces Good Bye B. New year and old property