![](/style/images/good.png)
5
![](/style/images/bad.png)
[Golang] Primality Test - Optimized School Method
source link: http://siongui.github.io/2017/04/19/go-primality-test-optimized-school-method/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
[Golang] Primality Test - Optimized School Method
April 19, 2017
Go implementation of primality test - optimized school method. [1]
package main import ( "fmt" ) func IsPrime(n int) bool { // Corner cases if n <= 1 { return false } if n <= 3 { return true } // This is checked so that we can skip // middle five numbers in below loop if n%2 == 0 || n%3 == 0 { return false } for i := 5; i*i <= n; i = i + 6 { if n%i == 0 || n%(i+2) == 0 { return false } } return true }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK