2039C1.md (2086B)
1 Source: https://codeforces.com/problemset/problem/2039/C1 2 3 C1. Shohag Loves XOR (Easy Version) 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 This is the easy version of the problem. The differences between the two versions are highlighted in bold. You can only make hacks if both versions of the problem are solved. 22 23 Shohag has two integers $x$ and $m$. Help him count the number of integers $1 \le y \le m$ such that $\mathbf{x \neq y}$ and $x \oplus y$ is a divisor$^{\text{∗}}$ of either $x$, $y$, or both. Here $\oplus$ is the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operator. 24 25 $^{\text{∗}}$The number $b$ is a divisor of the number $a$ if there exists an integer $c$ such that $a = b \cdot c$. 26 27 Input 28 29 The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. 30 31 The first and only line of each test case contains two space-separated integers $x$ and $m$ ($1 \le x \le 10^6$, $1 \le m \le 10^{18}$). 32 33 It is guaranteed that the sum of $x$ over all test cases does not exceed $10^7$. 34 35 Output 36 37 For each test case, print a single integer — the number of suitable $y$. 38 39 Example 40 41 Input 42 43 ``` 44 5 45 46 6 9 47 48 5 7 49 50 2 3 51 52 6 4 53 54 4 1 55 ``` 56 57 Output 58 59 ``` 60 3 61 2 62 1 63 1 64 0 65 ``` 66 67 Note 68 69 In the first test case, for $x = 6$, there are $3$ valid values for $y$ among the integers from $1$ to $m = 9$, and they are $4$, $5$, and $7$. 70 71 * $y = 4$ is valid because $x \oplus y = 6 \oplus 4 = 2$ and $2$ is a divisor of both $x = 6$ and $y = 4$. 72 * $y = 5$ is valid because $x \oplus y = 6 \oplus 5 = 3$ and $3$ is a divisor of $x = 6$. 73 * $y = 7$ is valid because $x \oplus y = 6 \oplus 7 = 1$ and $1$ is a divisor of both $x = 6$ and $y = 7$. 74 75 In the second test case, for $x = 5$, there are $2$ valid values for $y$ among the integers from $1$ to $m = 7$, and they are $4$ and $6$. 76 77 * $y = 4$ is valid because $x \oplus y = 5 \oplus 4 = 1$ and $1$ is a divisor of both $x = 5$ and $y = 4$. 78 * $y = 6$ is valid because $x \oplus y = 5 \oplus 6 = 3$ and $3$ is a divisor of $y = 6$.