Professional Documents
Culture Documents
Q1 B
Q2 C
Q3 C
Q4 C
Q5
Q6 C
Q7 D
Q8 B
CODING
Q1
#include <iostream>
using namespace std;
long long int count(int a, int b){
long long int cnt=0,n;
for(long long int i=a;i<=b;i++)
{
n=i;
while(n>0){
if((n&1)>0) cnt++;
n=n>>1;
}
return cnt;
}
int main() {
long long int a,b,q,c;
cin>>q;
while(q--){
cin>>a>>b;
c=count(a,b);
cout<<c<<endl;
}
return 0;
}
Q2
#include <iostream>
#include<math.h>
using namespace std;
int main(){
long long int n,flag=0,x,y=0;
cin>>n;
while(n>0){
x=n%10;
if(x==7){
flag=flag+ pow(2,y+1);
}
else
flag=flag+ pow(2,y);
y++;
n=n/10;
}
cout<<flag;
return 0;
}
Q3
#include <iostream>
#include<math.h>
using namespace std;
int main(){
long long int t,n,cnt=0;
cin>>t;
while(t--){
cin>>n;
while(n>0){
n = (n & (n << 1));
cnt++;
}
cout<<cnt<<endl;
cnt=0;
}
return 0;
}