#P15132. [ROIR 2026] 位魔法

    ID: 17043 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>位运算2026ROIR(俄罗斯)

[ROIR 2026] 位魔法

Problem Description

You are given three non-negative integers bb, ll, and rr, written in hexadecimal.

As a reminder, hexadecimal (base 1616) uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, where A corresponds to 1010, B to 1111, C to 1212, D to 1313, E to 1414, and F to 1515. For example, the hexadecimal number 1F equals 1⋅16+15=311 \cdot 16 + 15 = 31 (in decimal).

The operation &\mathbin{\&} denotes bitwise AND. Consider the binary representations of numbers xx and bb, padding leading zeros if necessary so that they have the same length. For each bit position ii:

$$(x \mathbin{\&} b)_i = \begin{cases} 1, & \text{if } x_i = 1 \text{ and } b_i = 1,\\ 0, & \text{otherwise.} \end{cases}$$

In other words, a bit in the result is 11 only when both numbers have 11 in the corresponding bit.

You need to find the number of integers xx such that l≤x≤rl \le x \le r and x&b=bx \mathbin{\&} b = b. Output this count modulo 109+710^9 + 7.

Input Format

The input consists of three lines: the first line is the number ll, the second line is the number rr, and the third line is the number bb.

Each number is given in hexadecimal, with no leading zeros (except when the number itself is 0), and consists of characters 0-9 and A-F. The length of each line does not exceed 50 00050\,000 characters. It is guaranteed that 0≤l≤r0 \le l \le r.

Output Format

Output one integer: the number of values xx that satisfy the conditions, modulo 109+710^9 + 7.

The answer should be written in decimal, without leading zeros.

8
F
5
2
2
F9
A
60

Hint

Sample Explanation

In the first sample, the values of xx that satisfy the condition are the hexadecimal numbers D and F.

Scoring

The points for each subtask are awarded only if that subtask and all of its required subtasks pass all testdata.

Subtask Points Additional Constraints Required Subtasks
1 10 0≤r,b<1640 \le r, b < 16^4, l=0l = 0
2 5 0≤l,r,b<1640 \le l, r, b < 16^4 1
3 10 0≤r,b<1670 \le r, b < 16^7, l=0l = 0
4 6 0≤l,r,b<1670 \le l, r, b < 16^7 1–3
5 10 0≤r,b<16150 \le r, b < 16^{15}, l=0l = 0 1, 3
6 7 0≤l,r,b<16150 \le l, r, b < 16^{15} 1–5
7 14 0≤r,b<1610000 \le r, b < 16^{1000}, l=0l = 0 1, 3, 5
8 7 0≤l,r,b<1610000 \le l, r, b < 16^{1000} 1–7
9 11 0≤r,b<1650 0000 \le r, b < 16^{50\,000}, l=0l = 0 1, 3, 5, 7
10 12 0≤l,r<1650 0000 \le l, r < 16^{50\,000}, b=0b = 0
11 8 0≤l,r,b<1650 0000 \le l, r, b < 16^{50\,000} 1–10

Translated by ChatGPT 5