Smallest Number with Fives
Time limit1sMemory limit128 MB
Find the smallest integer greater than N that contains the digit 5 at least K times in its decimal form.
- Level
Medium6 of 10
- Topics
- Math, Greedy, Brute force
- Solved
- No attempts yet
Problem
Given natural numbers N and K, find the smallest natural number greater than N whose decimal representation contains the digit 5 at least K times.
Input
The first line contains two natural numbers N and K separated by a space.
- 1 <= N <= 10^15
- 1 <= K <= 15
Output
Print the smallest natural number greater than N whose decimal representation contains the digit 5 at least K times.