试除法判定质数-golang
试除法判定质数-golang
package main
import "fmt"
var n int
func main(){
fmt.Scanf("%d", &n)
for i := 0; i < n; i++{
var num int
fmt.Scanf("%d", &num)
if isPrime(num){
fmt.Printf("Yes\n")
}else{
fmt.Printf("No\n")
}
}
}
func isPrime(x int)bool{
if x <2{
return false
}
for i := 2; i <= x/i; i++{
if x%i == 0{
return false
}
}
return true
}