Skip to content

Instantly share code, notes, and snippets.

@trhgquan
Created October 17, 2019 12:15
Show Gist options
  • Save trhgquan/4b3687adb70f2482713987a737d862f1 to your computer and use it in GitHub Desktop.
Save trhgquan/4b3687adb70f2482713987a737d862f1 to your computer and use it in GitHub Desktop.
/*
* https://www.spoj.com/problems/NUB04/
* Code by @trhgquan - https://github.com/trhgquan
*/
#include <iostream>
#define lli long long int
bool isPrime(lli a) {
if (a == 0 || a == 1) return false;
if (a == 2) return true;
for (lli i = 2; i * i <= a; ++i)
if (a % i == 0) return false;
return true;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
lli i;
while (std::cin >> i) {
if (isPrime(i)) std::cout << "YES" << std::endl;
else std::cout << "NO" << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment