题目链接:http://acm.bupt.edu.cn/onlinejudge/newoj/showProblem/show_problem.php?problem_id=1578
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset> using namespace std;
int a,b;
int calculatenum(int num){
int ans = ;
while(num>){
num = num/;
ans++;
}
return ans;
}
int calculateone(int num){
int ans = ;
while(num>){
if(num%) ans++;
num = num/;
}
return ans;
} int main(){
// if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} int T;
cin>>T;
while(T--){ cin>>a>>b; int numa = calculatenum(a);
int numb = calculatenum(b); if(a == b){
printf("%d\n",calculateone(b));
}
else if(b == (<<numb )- ){
printf("%d\n",numb);
}
else if(numa < numb) {
printf("%d\n",numb-);
}
else{
int maxnum = calculateone(b);
int temp = b;
numa--;
while(a>>numa == b>>numa){
temp = temp%(<<numa);
numa--;
}
numa++;
if(temp != (<<numa)-){
maxnum = calculateone(b / (<<numa)) + calculatenum(temp) - ;
}
printf("%d\n",maxnum);
} }
}