Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Suppose that the number that we are looking for has the same number of digits as n, the answer, in this case, will not be very far from n, so you can do a simple brute force. Can you prove why this is true?
How do you handle the case when the resulting number has more digits than n?