304043: CF776G. Sherlock and the Encrypted Data

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Sherlock and the Encrypted Data

题意翻译

$q$ 组询问,以 16 进制的形式给出 $L, R$,求出满足以下条件的整数 $x$ 的个数。 1. $L\leq x \leq R$。 2. $f(x) < x$。其中 $f(x)$ 定义如下: 设 $x$ 在 16 进制下的数位分别为 $\overline{d_k d_{k - 1} d_{k - 2} \cdots d_0}$,令 $y = \sum\limits_{i = 0} ^ {15} 2 ^ i[i\in d]$,则 $f(x) = x \oplus y$。换句话说,$f(x)$ 等于 $x$ 异或上 “$2$ 的 “所有在 $x$ 的 16 进制下出现的数码” 次幂之和”。 $1\leq q\leq 10 ^ 4$,$0\leq L\leq R < 16 ^ {15}$。

题目描述

Sherlock found a piece of encrypted data which he thinks will be useful to catch Moriarty. The encrypted data consists of two integer $ l $ and $ r $ . He noticed that these integers were in hexadecimal form. He takes each of the integers from $ l $ to $ r $ , and performs the following operations: 1. He lists the distinct digits present in the given number. For example: for $ 1014_{16} $ , he lists the digits as $ 1,0,4 $ . 2. Then he sums respective powers of two for each digit listed in the step above. Like in the above example $ sum=2^{1}+2^{0}+2^{4}=19_{10} $ . 3. He changes the initial number by applying bitwise xor of the initial number and the sum. Example: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF776G/959289a189ff1fca05b0806d5e720756eddc35a9.png). Note that xor is done in binary notation. One more example: for integer 1e the sum is $ sum=2^{1}+2^{14} $ . Letters a, b, c, d, e, f denote hexadecimal digits $ 10 $ , $ 11 $ , $ 12 $ , $ 13 $ , $ 14 $ , $ 15 $ , respertively. Sherlock wants to count the numbers in the range from $ l $ to $ r $ (both inclusive) which decrease on application of the above four steps. He wants you to answer his $ q $ queries for different $ l $ and $ r $ .

输入输出格式

输入格式


First line contains the integer $ q $ ( $ 1<=q<=10000 $ ). Each of the next $ q $ lines contain two hexadecimal integers $ l $ and $ r $ ( $ 0<=l<=r&lt;16^{15} $ ). The hexadecimal integers are written using digits from $ 0 $ to $ 9 $ and/or lowercase English letters a, b, c, d, e, f. The hexadecimal integers do not contain extra leading zeros.

输出格式


Output $ q $ lines, $ i $ -th line contains answer to the $ i $ -th query (in decimal notation).

输入输出样例

输入样例 #1

1
1014 1014

输出样例 #1

1

输入样例 #2

2
1 1e
1 f

输出样例 #2

1
0

输入样例 #3

2
1 abc
d0e fe23

输出样例 #3

412
28464

说明

For the second input, $ 14_{16}=20_{10} $ $ sum=2^{1}+2^{4}=18 $ ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF776G/9208143c550bbdde0f9599d03b249de570f4e364.png) Thus, it reduces. And, we can verify that it is the only number in range $ 1 $ to $ 1e $ that reduces.

Input

题意翻译

$q$ 组询问,以 16 进制的形式给出 $L, R$,求出满足以下条件的整数 $x$ 的个数。 1. $L\leq x \leq R$。 2. $f(x) < x$。其中 $f(x)$ 定义如下: 设 $x$ 在 16 进制下的数位分别为 $\overline{d_k d_{k - 1} d_{k - 2} \cdots d_0}$,令 $y = \sum\limits_{i = 0} ^ {15} 2 ^ i[i\in d]$,则 $f(x) = x \oplus y$。换句话说,$f(x)$ 等于 $x$ 异或上 “$2$ 的 “所有在 $x$ 的 16 进制下出现的数码” 次幂之和”。 $1\leq q\leq 10 ^ 4$,$0\leq L\leq R < 16 ^ {15}$。

加入题单

算法标签: