Primality by trial division: Difference between revisions

Content added Content deleted
No edit summary
Line 675: Line 675:


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang>trial(n)={
<lang parigp>trial(n)={
if(n%2 == 0, return(n==2));
if(n < 4, return(n > 1)); /* Handle negatives */
if(n < 9, return(n > 1));
forprime(p=2,sqrt(n),
forprime(p=3,sqrt(n),
if(n%p == 0, return(0))
if(n%p == 0, return(0))
);
);