Created
February 13, 2022 02:20
-
-
Save potat-dev/0a04602fd9ba136d44179d531447224f to your computer and use it in GitHub Desktop.
Primality test in C++
This file contains 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
int is_prime(int n) { | |
if (n < 3) return (n == 2); | |
if (~n & 1) return 0; | |
for (int i = 3; i*i <= n; i += 2) | |
if (n % i == 0) return 0; | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment