-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisPrime.cpp
59 lines (50 loc) · 899 Bytes
/
isPrime.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
using namespace std;
//Driver code
int main()
{
long long int n;
cin >> n;
bool flag = true;
for(long long int i=2; i<n; i++){
if(n%i==0){
flag = false;
break;
}
}
if(flag){
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
return 0;
}
// Or You can use below program
/*
#include <iostream>
#include <vector>
using namespace std;
//Driver code
int main()
{
long long int n,i;
cin >> n;
vector<bool>isPrime(n+1, true);
for(i=2; i<=n; i++){
if(isPrime[i]){
if(i==n){
cout << "Yes" << endl;
break;
}
for(long long int j= i*i; j<=n; j+=i){
isPrime[j] = false;
}
}
}
if(i!=n){
cout << "No" << endl;
}
return 0;
}
*/