Treat each new call to primeFactorsR as starting at the beginning each time.
It could either go to the if, in which case it would stop recursively calling the method.
It could go to the else if...
Type: Posts; User: javapenguin
Treat each new call to primeFactorsR as starting at the beginning each time.
It could either go to the if, in which case it would stop recursively calling the method.
It could go to the else if...
Once it hits 5, it then goes to finish off the other recursive calls left over.
For each of the recursive calls it had before it hit 5, it still has to call the second half that it had been...
That would depend if there were any more cases left, as you're still calling the method.
It would have to go through all calls that might be entailed with
primeFactorsR(n/m, (n/m)-1);
...
As It will be calling
primeFactorsR(m, m-1);
primeFactorsR(n/m, (n/m)-1);
And will call
primeFactorsR(m, m-1);
until it is done, before...
Try adding println's.
public class Tester {
static boolean isPrime(int p)
{
for(int i = 2; i < p; i++)
{
if(p % i == 0)