Wonderprime Brands
Time limit1sMemory limit128 MB
Given D and N, find the smallest integer at least N whose digit string splits into two primes of length at least D, neither with a leading zero.
- Level
Medium7 of 10
- Topics
- Number theory, Brute force, Math, Implementation
- Solved
- No attempts yet
Problem
The cows are forever competing to see who has the best brand, and the latest craze is a brand that is a "wonderprime". A brand is a sequence of digits that does not begin with , so it looks just like a positive integer.
A wonderprime is a positive integer whose digit string can be split into two consecutive parts — a left part and a right part, whose concatenation is the original number — such that both parts are prime, each part has at least digits, and neither part begins with .
For example, when , the number is a wonderprime, because it splits into and , both of which are prime.
Given an integer , find the smallest wonderprime that is greater than or equal to . It is guaranteed that and that the answer never exceeds .
Input
The first line contains two space-separated integers and .
Output
Print the smallest wonderprime that is no smaller than .