#P1898. 缘分计算
缘分计算
Description
Step 1: Take the initials (abbreviation) of the names and concatenate them. For example, if the lovers are named JiangYunFan and TangYuRou, their initials are JYFTYR.
Step 2: Replace each letter with a string of digits. Replace with , with , with , …, and with , where is a known positive integer. For example, if , then is replaced by , by , …, and by . The example JYFTYR becomes .
Step 3: Repeat the following operation: add each pair of adjacent digits, and write down the ones digit of the sum. It is easy to see that each time this operation is performed, the digit string becomes one digit shorter. When the number becomes or has no more than two digits (a two-digit number with a leading also counts), the program stops. The resulting number is the couple’s yuanfen. For the example above, the process is as follows:
- 901058610010598;
- 91153471011547;
- 0268718112691;
- ...
- 374;
-
So if , the yuanfen between JiangYunFan and TangYuRou is only .
Oh no! DL knows 644 very well. He knows that even if the program calculates a yuanfen as high as , she still won’t be happy. What’s worse, 644 is also curious about the yuanfen of many other couples, and it would be too tedious to compute them one by one. Given the couple’s initials string and a value of , can you write a program to compute their yuanfen?
Input Format
The first line contains a string of length consisting only of uppercase letters.
The second line contains a positive integer , as defined in the statement.
Output Format
Output a single line containing an integer, which is the couple’s yuanfen.
DLLSS
478
100
Hint
Constraints
For of the testdata, , .
Note
If your yuanfen with your lover is not , don’t be sad. It’s not a big deal.
Translated by ChatGPT 5
京公网安备 11011102002149号