give me a piece of code in golang that calculates the next prime number above 10000
- User
give me a piece of code in golang that calculates the next prime number above 10000
Assistant
Sure, here is a simple Go program that calculates the next prime number above a given number:
gopackage main import ( "fmt" "math" ) func isPrime(n int) bool { if n <= 1 { return false } if n == 2 { return true } if n%2 == 0 { return false } for i := 3; i*i <= n; i += 2 { if n%i == 0 { return false } } return true } func nextPrimeAbove(n int) int { i := n + 1 for { if isPrime(i) { return i } i++ } } func main() { next := nextPrimeAbove(10000) fmt.Printf("The next prime number above 10000 is: %d\n", next) }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.