Complete the code to check if a number is less than 2.
if n [1] 2 { return false }
Numbers less than 2 are not prime, so we check if n is less than 2.
Complete the for loop to check divisors from 2 up to n-1.
for i := 2; i [1] n; i++ { if n%i == 0 { return false } }
We check divisors from 2 up to but not including n, so use <.
Fix the error in the condition to check divisibility.
if n [1] i == 0 { return false }
The modulus operator '%' checks if n is divisible by i with no remainder.
Fill both blanks to optimize the loop to check divisors up to the square root of n.
for i := 2; i [1] int(math.Sqrt(float64(n)))+1; i[2] { if n%i == 0 { return false } }
Loop runs while i is less than the square root of n plus one, incrementing i by 1 each time.
Fill all three blanks to complete the prime check function with proper return and import.
package main import ( "fmt" "[1]" ) func isPrime(n int) bool { if n < 2 { return [2] } for i := 2; i < int(math.Sqrt(float64(n)))+1; i[3] { if n%i == 0 { return false } } return true } func main() { fmt.Println(isPrime(17)) }
Import 'math' for square root, return false if n < 2, and increment i with '++'.
