#5440. Problem 2. Strange Function
Problem 2. Strange Function
Problem 2. Strange Function
USACO 2026 Third Contest, Bronze
For all positive integers , the function is defined as follows:
- If has any digits that aren't or , for each digit of , set it to if it is odd or otherwise, and return .
- Otherwise, return .
Given a value of (), find how many times needs to be applied to until reaches . As this number might be very large, output its remainder when divided by .
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains (), the number of independent tests.
The next lines each contain a positive integer consisting solely of the digits 0-9, with no leading zeros.
It is guaranteed that the total number of digits in all input integers does not exceed .
OUTPUT FORMAT (print output to the terminal / stdout):
For each test case, output the remainder of the number of times when divided by on a separate line.
SAMPLE INPUT:
2 24680 210
SAMPLE OUTPUT:
1 4
First test: becomes zero after one operation.
Second test:
SAMPLE INPUT:
1 1234567890123456789012345678901234567890
SAMPLE OUTPUT:
511620083
SCORING: Inputs 3-5: , Inputs 6-7: Inputs 8-9: Inputs 10-12: No additional constraints.
Problem credits: Aidan Bai