mirror of https://github.com/01-edu/public.git
Xavier Petit
4 years ago
committed by
xpetit
5 changed files with 11 additions and 28 deletions
@ -1,24 +1,8 @@ |
|||||||
package correct |
package correct |
||||||
|
|
||||||
import "math" |
func FindNextPrime(nb int) int { |
||||||
|
if isPrime(nb) { |
||||||
func isPrime(value int) bool { |
return nb |
||||||
if value < 2 { |
|
||||||
return false |
|
||||||
} |
|
||||||
limit := int(math.Floor(math.Sqrt(float64(value)))) |
|
||||||
i := 2 |
|
||||||
for i <= limit { |
|
||||||
if value%i == 0 { |
|
||||||
return false |
|
||||||
} |
|
||||||
i++ |
|
||||||
} |
|
||||||
return true |
|
||||||
} |
|
||||||
func FindNextPrime(value int) int { |
|
||||||
if isPrime(value) { |
|
||||||
return value |
|
||||||
} |
} |
||||||
return FindNextPrime(value + 1) |
return FindNextPrime(nb + 1) |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue