Created
December 30, 2022 16:45
-
-
Save Elerphore/ee517a51d3feaae7064be3bc61beebe6 to your computer and use it in GitHub Desktop.
Optimized prime number algorithm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlin.math.sqrt | |
| fun main() { | |
| val number = sqrt(17f).toInt() | |
| var isPrime = true | |
| for(i in 3 .. number step 2) { | |
| if(number % i == 0) { | |
| isPrime = false | |
| } | |
| } | |
| println(isPrime) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good explonation:
https://www.baeldung.com/java-find-if-square-root-is-integer