Square-Substring-Free Number
Time limit1sMemory limit1024 MB
Given N up to 10^18, find the smallest number at least N whose decimal representation contains no perfect square as a substring.
- Level
Hard8 of 10
- Topics
- Dynamic programming, String matching, Greedy
- Solved
- No attempts yet
Problem
For an integer , write in decimal notation. A positive integer is called a square-substring-free number if none of those decimal strings appears as a substring of the decimal representation of .
In increasing order, these numbers begin as .
Given a positive integer , find the smallest square-substring-free number that is at least .
Input
A positive integer is given.
Output
Print the smallest square-substring-free number that is at least .