I have a function recursively defined as follows:
$a_{n+1}-1=(a_n-1)\times lpf(a_n)$, whe $lpf(x)$ is the least prime factor of $x$.
Now, given an initial value of $a_0$, I would like to find the smallest value of $a_n$ such that $a_n$ is prime.
Here is my attempt at a code, with $a_0=6$.
NestWhileList[((#1 - 1)*FactorInteger[#1][[1, 1]] + 1) &, 6, ! PrimeQ]
However, my code always simply returns the initial value of $a_0$. What am I doing wrong here?
Last@NestWhileList[((#1 - 1)*FactorInteger[#1][[1, 1]] + 1) &, 6, Not[PrimeQ[#]] &]? – b.gatessucks Mar 2 at 8:25Not[PrimeQ[#]] &does the trick! Any idea why! PrimeQdoesn't, however? – Vincent Tjeng Mar 2 at 8:33