-
Notifications
You must be signed in to change notification settings - Fork 0
/
Check.cpp
53 lines (50 loc) · 926 Bytes
/
Check.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
/**
*
* @Name : isPrime/Check.cpp
* @Version : 1.0
* @Programmer : Max
* @Date : 2019-04-25
* @Released under : https://github.com/BaseMax/isPrime/blob/master/LICENSE
* @Repository : https://github.com/BaseMax/isPrime
*
**/
#include <iostream>
#include <iostream>
// using namespace std;
using std::cin;
using std::cout;
bool isPrime(int number) {
int count=0;
for(int index=2; index<number; index++) {
if(number % index == 0) {
count++;
}
}
if(count == 0) {
return true;
}
return false;
}
bool isPrimeBetter(int number) {
if(number <= 1)
return false;
if(number % 2 == 0 && number > 2)
return false;
for(int i = 3; i < number / 2; i+= 2) {
if(number % i == 0)
return false;
}
return true;
}
int main() {
int number;
cout << "> ";
cin >> number;
for(int index=1; index<=number; index++) {
// if(isPrime(index)) {
if(isPrimeBetter(index)) {
cout << index << "\n";
}
}
return 0;
}