2020-05-28 04:45:33 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Compute prime numbers upto 1 billion
|
|
|
|
* @see prime_numbers.cpp sieve_of_eratosthenes.cpp
|
|
|
|
*/
|
2019-12-07 15:33:23 +08:00
|
|
|
#include <cstring>
|
2020-05-26 10:13:39 +08:00
|
|
|
#include <iostream>
|
2019-12-07 15:33:23 +08:00
|
|
|
|
2020-05-28 04:45:33 +08:00
|
|
|
/** array to store the primes */
|
2019-12-07 15:33:23 +08:00
|
|
|
char prime[100000000];
|
|
|
|
|
2020-05-28 04:45:33 +08:00
|
|
|
/** Perform Sieve algorithm */
|
2020-05-30 07:26:30 +08:00
|
|
|
void Sieve(int64_t n)
|
|
|
|
{
|
2019-12-07 15:33:23 +08:00
|
|
|
memset(prime, '1', sizeof(prime)); // intitize '1' to every index
|
2020-05-26 10:13:39 +08:00
|
|
|
prime[0] = '0'; // 0 is not prime
|
|
|
|
prime[1] = '0'; // 1 is not prime
|
2020-05-30 07:26:30 +08:00
|
|
|
for (int p = 2; p * p <= n; p++)
|
|
|
|
{
|
|
|
|
if (prime[p] == '1')
|
|
|
|
{
|
2019-12-07 15:33:23 +08:00
|
|
|
for (int i = p * p; i <= n; i += p)
|
|
|
|
prime[i] = '0'; // set all multiples of p to false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 04:45:33 +08:00
|
|
|
/** Main function */
|
2020-05-30 07:26:30 +08:00
|
|
|
int main()
|
|
|
|
{
|
2019-12-07 15:33:23 +08:00
|
|
|
Sieve(100000000);
|
|
|
|
int64_t n;
|
|
|
|
std::cin >> n; // 10006187
|
|
|
|
if (prime[n] == '1')
|
|
|
|
std::cout << "YES\n";
|
|
|
|
else
|
|
|
|
std::cout << "NO\n";
|
2020-05-28 04:45:33 +08:00
|
|
|
|
|
|
|
return 0;
|
2019-12-07 15:33:23 +08:00
|
|
|
}
|