Last active
February 14, 2022 20:00
-
-
Save soroush/54169f9181d051e37e39ad27c1f06b7d to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
bool test_prime(const uint64_t n) | |
{ | |
if (n == 2 || n == 3) | |
return true; | |
if (n <= 1 || n % 2 == 0 || n % 3 == 0) | |
return false; | |
for (uint64_t i = 5; i * i <= n; i += 6) | |
{ | |
if (n % i == 0 || n % (i + 2) == 0) | |
return false; | |
} | |
return true; | |
} | |
int main(int argc, char const* argv[]) | |
{ | |
std::cout << std::boolalpha << test_prime(11) << '\n'; | |
std::cout << std::boolalpha << test_prime(321564613654653) << '\n'; | |
std::cout << std::boolalpha << test_prime(27644437) << '\n'; | |
std::cout << std::boolalpha << test_prime(276444378) << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment