Prime Numbers
Practice
3 (3 votes)
Mathematics
Easy Medium
Shortest path problem
Factorization
Problem
4% Success 349 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

The author of this problem hopes that you still have not forgotten about the pig called Benny :)

Recently, she started learning numbers. The first type of numbers she has learnt is "Prime" numbers. The number is called prime if it has only 2 divisors including 1 and itself.

As a homework Benny was given two integers A and B. She has to transform A into B using addition and subtraction.

Here is only one restriction: since Benny knows only prime numbers she might add and subtract only prime numbers. Moreover, all the partial results also have to be prime numbers.

Your task is no find the way how Benny can transform number A into B with minimal number of additions and subtractions. If there are multiple ways - output "Poor Benny". If there is no way to transform A into B output "Unlucky Benny". Otherwise output the transformation with all partial results i.e you have to output A then -> then number in transformation then -> again and so on. The last number has to be equal to B. In other words A, B and any other temporary values during transformations should be separated by ->.

Input

The input data consists of only one single line containing two integers denoting A and B respectively.

Output

In a single line output the answer to the problem.

Constraints

  • 2A < B1015

It's guaranteed that A and B are prime numbers.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
Tags:
MathematicsSieveEasy-MediumNumber TheoryFactorization
Points:30
11 votes
Tags:
Prime FactorizationEasy-MediumMathematics
Points:30
5 votes
Tags:
MathematicsApprovedEasy-MediumFactorization