forked from ccgcv/Cplus-plus-for-hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsieve.cpp
More file actions
31 lines (30 loc) · 672 Bytes
/
sieve.cpp
File metadata and controls
31 lines (30 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main()
{
bool prime[100000 + 1];
memset(prime, true, sizeof(prime));
for (ll p = 2; p * p <= 100000; p++)
{
if (prime[p] == true)
{
for (ll i = p * p; i <= 100000; i += p)
prime[i] = false;
}
}
prime[1] = false;
cout << "Enter a number less than 100000\n";
int in;
cin >> in;
if (in > 100000 || in < 1)
cout << "Invalid Input\n";
else
{
if (prime[in])
cout << "The number is prime\n";
else
cout << "The number is not prime\n";
}
return 0;
}