#P7379. [COCI 2018/2019 #6] Lun
[COCI 2018/2019 #6] Lun
Description
There is an algorithm to check whether a certain bank card number is valid:
- Starting from the second-to-last digit, move from right to left. Multiply every other digit by ; keep the remaining digits unchanged.
- For each digit that was multiplied by , compute the sum of its digits.
- Compute the sum of all digits after the above operations, then multiply it by and take modulo . Check whether the result equals the last digit (i.e., the check digit of the bank card number).
If the card number to be verified is , the checking process is as follows:
| Digits of the card number | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Multiply by every other digit (starting from the second-to-last digit, moving left) | - | ||||||||||
| Compute digit sums and accumulate | |||||||||||
Multiply the obtained sum by and take modulo , getting . Here is the check digit of this card number, so the original card number is valid.
Now you are given a bank card number with one digit missing. According to the algorithm above, fill in a suitable digit at the missing position so that the resulting card number is valid.
Input Format
The first line contains an integer , representing the length of the bank card number with one missing digit.
The second line contains a string of length , representing the bank card number. The string contains only digits and the character x. The character x appears exactly once, indicating the missing digit.
Output Format
Output a digit that satisfies the requirement. If there are multiple valid digits, output the smallest one.
11
7992739871x
3
5
x2464
5
10
93380x1696
1
Hint
Constraints
For of the testdata, the missing digit is at the check digit position, i.e., the character x is at the last position of the string.
For of the testdata, .
Notes
The scoring of this problem follows the original COCI problem, with a full score of .
Translated from COCI2018-2019 CONTEST #6 T1 Lun.
Translated by ChatGPT 5
京公网安备 11011102002149号