Section: 2, Score: 19, Time limit per test: 30 seconds, Memory limit per test: 512MB, Input: stdin, Output: stdout
Agoda hosts 2 million+ properties on its platform. The best ones are called “prime property”, which provide a unique, comfortable stay to the guests and have a good customer rating.
In another parallel (mathematical) universe, all hotels are located on an infinite number line. And the prime properties are the ones located at prime coordinates. For example, a hotel at coordinate 3 is a prime property but another hotel at coordinate 10 is not.
Here is how it appears visually
Ms. Agoji is our regular customer. She is really into Prime properties and is staying in one of them right now. She has booked another prime property for tomorrow, but she is concerned whether she can get there or not, given she only travels prime distances, one at a time. She is OK with breaking her journey but only at other prime properties.
For example, if she needs to go from hotel 5 (prime) to hotel 3 (prime), she can directly go as she needs to travel 2 units (which is also a prime number).
However, if she needs to go from hotel 3 (prime) to hotel 7 (prime), she should first go to hotel 5 (prime) and then to hotel 7 (prime), each time travelling 2 units (which is also prime).
Given she is our loyal customer, please help her come up with the journey she should take to go from her current hotel to her next hotel tomorrow. If it is possible for her to reach her destination hotel, print the sequence of coordinates she needs to take. If it is not possible, display an apology message “Sorry Ms. Agoji!”.
One line containing
It is guaranteed that both
One line, containing the path Ms. Agoji can take to reach from hotel X to hotel Y. If there is more than one path, print the one with the least number of stops. If no such path exists, display the message “Sorry Ms. Agoji!”.
5 3
5 3
She can travel 2 units (which is prime) from hotel 5 to reach hotel 3.
3 7
3 5 7
She can first travel 2 units (which is prime) to reach hotel 5. From there, she can travel 2 units to reach hotel 7.