#P15132. [ROIR 2026] 位魔法
[ROIR 2026] 位魔法
Problem Description
You are given three non-negative integers , , and , written in hexadecimal.
As a reminder, hexadecimal (base ) uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, where A corresponds to , B to , C to , D to , E to , and F to . For example, the hexadecimal number 1F equals (in decimal).
The operation denotes bitwise AND. Consider the binary representations of numbers and , padding leading zeros if necessary so that they have the same length. For each bit position :
$$(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 only when both numbers have in the corresponding bit.
You need to find the number of integers such that and . Output this count modulo .
Input Format
The input consists of three lines: the first line is the number , the second line is the number , and the third line is the number .
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 characters. It is guaranteed that .
Output Format
Output one integer: the number of values that satisfy the conditions, modulo .
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 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 | , | |
| 2 | 5 | 1 | |
| 3 | 10 | , | |
| 4 | 6 | 1–3 | |
| 5 | 10 | , | 1, 3 |
| 6 | 7 | 1–5 | |
| 7 | 14 | , | 1, 3, 5 |
| 8 | 7 | 1–7 | |
| 9 | 11 | , | 1, 3, 5, 7 |
| 10 | 12 | , | |
| 11 | 8 | 1–10 |
Translated by ChatGPT 5