Okay. First store to L₁ a list of all 48 numbers relatively prime to 210, and between 11 and 210+11. The last element will be 211. You can do this in a subprogram, or at the start of the main program. If you choose the latter, compressing it in the form cumSum(11,2,4,… is possible and is what I did.
//First we check if there are divisors less than 211, including 2, 3, 5, and 7.
//The reason we don't use the list the first time is so that a number like 191 won't be divided by 191—it'll stop at 13.
//Now we don't need to check any possible divisors that are divisible by 2, 3, 5, or 7.
//We can just use the list, and keep shifting it up by 210 to catch all the possible divisors.
For(B,210,√(X),210) //keep the parenthesis on for If speed. Remember that √(X) is only computed once, at the start of the For loop.
If min(remainder(X,B+L₁ //if ALL of the remainders are greater than zero; in other words, if there's no divisor
End //Executed if the If is true, of course. As long as B<sqrt(X) it will jump back to the For( for the next batch of numbers.
//This way the parser doesn't need to skip a :Return every time it doesn't find a divisor.
B>√(X //This returns 1 if the loop went all the way, and 0 if it ended prematurely because it didn't see an End.
//Since there's no End here, the program will forget it was in a loop (if it was) and quit with the answer.
Without comments, it looks like this:
Yes, the parser works like this with the If… :End. It was strange to me too.
There's a slightly better way to try the numbers below 210, but I can't remember it right now. Also, I may have missed an edge case.
Try this with X=8675309. I don't have my calculator with me, but it should return 1 in less than five seconds.
EDIT: You probably knew this, but remainder(X,M can be replaced with fPart(X/M.
Also, if you want to turn this into a prime factorization program, you can use
where Ans is L₁+B, to find which number was the divisor. This works because all of the other numbers in the list will have something really large added to them, so the least one will be the divisor.
EDIT AGAIN: Credit to someone named "Anders Tiberg" and their program "PRIMEC1", which can be found on ticalc, which has some of these ideas in it.