-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprime.cpp
61 lines (54 loc) · 1.25 KB
/
prime.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
60
61
/***********************************************************
* @名称: 创建质数
* @作者: Shawn
* @创建时间: 2018-01-08 19:48:54
* @修改人: Shawn
* @修改时间: 2018-01-08 19:48:54
* @备注:
* @题目来源:
***********************************************************/
#include <cstdio>
#include <cstdlib>
#include <set>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
ofstream fout("prime.out");
int main()
{
long long length = 1, nowNum = 3;
vector<long long> prime;
prime.push_back(2);
while (length < 1e6)
{
bool ok = true;
for (long long i = 1; i <= length - 1; ++i)
{
long long temp = prime[i];
if (temp > nowNum / 2)
{
ok = true;
break;
}
else if (nowNum % temp == 0)
{
ok = false;
break;
}
}
if (ok == true)
{
prime.push_back(nowNum);
++length;
}
nowNum += 2;
}
for (long long i = 0; i <= length - 1; ++i)
{
fout << prime[i] << '\n';
}
return 0;
}