JY's Topic
"Problem Background"
One day, Jy felt Dzy iq too low, decided to divorce him, unless Dzy to make her out of the topic. Dzy of course very want and jy together, so he had to please computer God WJC Help, WJC has helped him several times busy, don't want to help him again. Dzy heard that your programming is also good, so found you. Your task is: To help Dzy solve the problem of JY.
"JY's topic"
"Problem description"
Given two decimal positive integers a and B, calculate how many bits of a and B are different when they are represented in binary notation.
For example, the binary representation of "3" is "11", "9" is represented as "1001", "11" is less than 4 bits, the less part is actually 0, or "0011", so the two are different from right to left 2nd and 4, so 3 and 9 are different in binary notation.
"Input description"
The input consists of two lines, and the 1th line is an integer n, which indicates that there are n sets of test data. Immediately following n rows, each line consists of two decimal positive integers a and b,a, b separated by A space.
"Output description"
The output has n rows and is a different number of bits in binary representation of a and B in each set of test data.
"Sample Input"
1
3 9
"Sample Output"
2
Solving the puzzle: directly to the binary belt comparison just fine.
Code:
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm>using namespace std; const int inf=0x3f3f3f3f; #define SI (x) scanf ("%d", &x) #define SL (x) scanf ("%lld", &x) #define PI (x) printf ("%d", X ) #define PL (x) printf ("%lld", x) #define MEM (x, y) memset (x,y,sizeof) #define P_ printf ("") typedef long Long Ll;int main ( {int N,a,b;si (n), while (n--) {si (a); Si (b); int Ans=0;while (a| | b) {if (a%2!=b%2) ans++;a/=2;b/=2;} printf ("%d\n", ans);} return 0;}
JY's topic (water)