Skip to content

Instantly share code, notes, and snippets.

@Moderrek
Created February 13, 2024 14:07
Show Gist options
  • Save Moderrek/aef5fc81a337d5c75db8a38a1519803f to your computer and use it in GitHub Desktop.
Save Moderrek/aef5fc81a337d5c75db8a38a1519803f to your computer and use it in GitHub Desktop.
#include <iostream>
bool is_prime(unsigned long long n) {
if (n <= 1) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (int i = 3; i * i <= n; i += 2)
if (n % i == 0) return false;
return true;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
unsigned long long n = 0;
std::cin >> n;
std::cout << (is_prime(n) ? "true" : "false") << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment