Solution 1:

https://mail-attachment.googleusercontent.com/attachment/?ui=2&ik=d860272f52&view=att&th=1377ee83b77f21fe&attid=0.1&disp=inline&realattid=f_h2ltntdx0&safe=1&zw&saduie=AG9B_P8uPzelpU1LhLRsIhOPqY2S&sadet=1337869307510&sads=h0-lBxxRSr2ieDrKqhhlK1j0axM ${}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}$

Solution 2:

We have that $677$ is obviously not divisible by $2, 3$, or $5$. Subtracting $77$ leaves $600$ which is not divisible by $7$ or $11$. Adding $13$ to it leaves $690$ which also reduces it to thinking about the two digit number $69$. Likewise subtracting $17$ from this number leaves $660$, and $66$ is not divisible by $17$, and subtracting $57$ leaves $620$ and $62$ is not divisible by $19$, so we reject $19$. Finally, adding $23$ gives $700$, so we reject that, and there's no occasion to go higher than $23$ since we have that $\lfloor\sqrt{677}\rfloor = 26$ so we need only check up to $23$.

As a bonus let's try $977$ which is prime. We have that $977$ is obviously not divisible by $2, 3$, or $5$. Subtracting $77$ leaves $900$ which is not divisible by $7$ or $11$, which also reduces it to thinking about the two digit number $90$ which is neither divisible by $7$ or $11$. Adding $13$ to it leaves $990$ which also reduces it to thinking about the two digit number $99$. Likewise subtracting $17$ from this number leaves $960$, and $96$ is not divisible by $17$, and subtracting $57$ leaves $920$ and $92$ is not divisible by $19$, so we reject $19$. Adding $23$ gives $1000$, so we reject that. Subtracting $87$ leaves $890$ and $89$ is not divisible by $29$, so we reject $29$. Finally, adding $93$ to $977$ gives us $1070$ and $107$ is not divisible by $31$ so we reject $31$ as well. Since we have that $\lfloor\sqrt{977}\rfloor = 31$, we need only check up to $31$ so we are done.

Solution 3:

This quicker primality test can be done for numbers in any arithmetic progression. For example, rather than $577$ let's consider more generally numbers of the form $\rm\:m = 10\:\!n \!-\! 3.\:$ Because we are considering only $1/10$ of the integers, we can effectively reduce an Eratosthenes sieve primality test on $\rm\:m\:$ to a sieve on an integer roughly $1/10\,$'th the size of $\rm\:m,\:$ namely $\rm\:n.\:$ Indeed, we have

Theorem $\ $ If the positive integer $\rm\ m\: =\: 10\:\!n\!-\!3 < 841 = 29^2\:$ then

$$\rm 10\:\!n\!-\!3\ \ is\ prime\iff 3\nmid n,\ \: 7\nmid n\!-\!1,\ \: 11\nmid n\!+\!3,\:\ 13\nmid n\!+\!1,\:\ 17\nmid n\!-\!2,\:\ 19\nmid n\!-\!6,\:\ 23\nmid n\!+\!2 $$

Proof $\ $ Since $\rm\:m < 29^2,\:$ if it is composite it must be divisible by a prime $\rm\:p < 29,\:$ hence $\rm\:p \le 23.\:$ Consider, e.g. $\rm\:p = 13\:|\:10\:\!n\!-\!3\iff 13\:|\:10\:\!n\!-\!3\!+\!13 = 10(n\!+\!1)\iff 13\:|\:n\!+\!1,\:$ etc. $\ \ $ QED

Your example $\rm\:577 = 10\cdot 58 - 3\:$ so the above primality test amounts to checking if any of the above $7$ primes divide $\rm\: 58\pm k,\:$ for $\rm\:k\le 6,\:$ which can be done very quickly mentally, as you did.

Solution 4:

There is a very nice paper about this, Guy, Lacampagne, and Selfridge, Primes at a glance, Mathematics of Computation Vol. 48, No. 177, Jan., 1987, pages 183 to 202. I think that back issues of this journal are freely available at the American Mathematical Society website.

There is a follow-up paper by Agoh, Erdos, and Granville, Primes at a (somewhat lengthy) glance, The American Mathematical Monthly Vol. 104, No. 10, Dec., 1997, pages 943 to 945, but I'm pretty sure that one's behind a paywall if you don't connect from a subscriber.


EDIT: Link to Primes at a glance mentioned above.

Solution 5:

can't resist following the pattern: 877. Additionally, need to test for 29 (but trivial)