The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...
Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).
For a given integer n >= 2:
- Let
fbe the position of the frog. It is initially set ton - if
f = 3orf = 19: the frog stops jumping - halt the program and outputf. - if
fis prime : the frog jumps to the position2×f-1. Go back to step 2. - if
fis composite : letdbef's biggerbiggest prime divisor. The frog jumps to the positionf-d. Go back to step 2.
Examples:
An example with n = 5:
5 > 9 > 6 > 3 stop The program should output 3.
Another example with n = 23:
23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop Again, the program should output 3.
Test cases:
10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 You can assume 1 < n < 1000000 (I have checked the program ends for these values).