Submit | All submissions | Best solutions | Back to list |
SKS001 - Secret Recipe |
Harsh and Vishal are besties. Vishal has a secret recipe which would land both of them a job. But he his unwilling to share his recipe.
Both of them are standing on the positive side of x-axis. Harsh is on coordinate i and Vishal on j (i <= j). Harsh can make two kinds of moves, if he is standing on coordinate m he could either move to m+1 or a coordinate n such that n is prime. The cost of jumping is the value of the coordinate on which Harsh jumps.
Vishal would give his recipe only if Harsh reaches him in minimum total cost. Help Harsh out.
Input
The first line of input contains two integers i and j (i <= j) as mentioned above.
0 <= i, j <= 2*10^9
Output
Output a single line containing minimum cost to reach j from i.
Example
Input: 2 4 Output: 7
Added by: | Shuvam |
Date: | 2018-07-24 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Own |
hide comments
2022-01-24 20:35:32 David
You are correct, @akjol2049. Cannot move backward by 1. Problem statement is only forward by 1 or jump to prime. |
|
2018-11-09 12:50:38
he cant move backwards..(to m-1) right? Last edit: 2018-11-09 12:51:15 |
|
2018-10-04 20:17:45
hints |