-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquadcore.cpp
57 lines (48 loc) · 1007 Bytes
/
quadcore.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
// g++ -std=c++11 -pthread
#include <iostream>
#include <thread>
#include <atomic>
#include <fstream>
using namespace std;
void prime(atomic_int& n){
int i, z = 1, t=n;
bool isprime = true;
n.fetch_add(1000);
t=n;
while(z<1000){
for (i = 2; i <= t / 2; ++i) {
if ( t % i == 0) {
isprime = false;
break;
}}
if (isprime){
ofstream myfile("50mil.txt", std::ios_base::app);
myfile<<t<<endl;
myfile.close();
}
else{
isprime=true;}
t=t+1;
n=t;
}}
int main() {
int g, i,z = 1;
bool isPrime = true;
cin>>g;//starting number
g=g-1000;
atomic_int n(g);
thread first (prime, ref(n));
thread second (prime, ref(n));
thread third (prime,ref(n));
thread fourth (prime, ref(n));
first.join();
second.join();
third.join();
fourth.join();
while(n<10000){
thread first (prime, ref(n));
thread second (prime, ref(n));
thread third (prime, ref(n));
thread fourth (prime, ref(n));
}
return 0;}