Advertisement
Guest User

primetest

a guest
May 14th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. Define primetest(n)=
  2. Func
  3. :If mod(n,3)=0 or mod(n,7)=0:Return false
  4. :Local s,d,i,j,k,rem,wit,nm
  5. :nm:=n-1
  6. :k:=2
  7. :If n>1373652 Then
  8. : k:=4
  9. : If n>118670087466:k:=7
  10. :EndIf
  11. :s:=0
  12. :d:=n-1
  13. :While (d and 1)=0
  14. : s:=s+1
  15. : d:=intDiv(d,2)
  16. :EndWhile
  17. :For i,1,k
  18. : rem:=exprem({2,3,5,7,11,13,17}[i],d,n)
  19. : If rem≠1 and rem≠nm Then
  20. : wit:=true
  21. : For j,1,s-1
  22. : rem:=mod(rem*rem,n)
  23. : If rem=nm Then
  24. : wit:=false
  25. : Exit
  26. : EndIf
  27. : EndFor
  28. : If wit=true:Return false
  29. : EndIf
  30. :EndFor
  31. :Return true
  32. :EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement