-
Notifications
You must be signed in to change notification settings - Fork 17
/
Playing with bits.cpp
42 lines (37 loc) · 838 Bytes
/
Playing with bits.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Prateek Bhayia likes to play with bits. One day Prateek bhayia decides to assign a task to his student Sanya.
You have help Sanya to complete this task. Task is as follows - Prateek Bhayia gives Q queries each query containing two integers a and b.
Your task is to count the no of set-bits in for all numbers between a and b (both inclusive)
Input Format
Read Q - No of Queries, Followed by Q lines containing 2 integers a and b.
Constraints
Q,a,b are integers.
Output Format
Q lines, each containing an output for your query.
Sample Input
2
1 1
10 15
Sample Output
1
17
*/
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int p,n,o=0,m,z=0;
cin>>p>>m;
for(n=p;n<=m;n++)
{ o=__builtin_popcount(n);
z+=o;
//cout<<o<<"\n";
} cout<<z<<"\n";
}
return 0;
}