B. Another Divisibility Problem
Problem
Alice and Bob are playing a game. Alice gives Bob a positive integer .
To win, Bob must find a positive integer such that the number formed by concatenating and (denoted as ) is divisible by .
For example, if and , then (the number formed by writing 835 followed by 47).
It can be proven that such a always exists. Help Bob find one such .
Input
- One integer ()
Output
- One integer () such that is divisible by
Solution
Key Observations
- For a number with digits, concatenating to is equivalent to computing:
- We need to find such that
- One strategy is to try for some integer , which makes
Solution Strategy
Set
- Then
- And is concatenated with
- This often works and gives a smaller answer