Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <string.h>
- #include <stdio.h>
- #include <conio.h>
- #include "pch.h"
- #include <iostream>
- #include <Windows.h>
- using namespace std;
- struct Date {
- int min, max;
- char filename[10];
- };
- DWORD WINAPI Function(LPVOID lpParam) {
- bool p;
- Date *data = (Date*)lpParam;
- int i = data->min;
- int n = data->max;
- char* plik = data->filename;
- strcat(plik, ".txt");
- FILE * file = fopen(plik, "a");
- for (i ; i < n; i++)
- {
- p = true;
- for (int j = 2; j < i; j++)
- if (i % j == 0)
- p = false;
- if (p == true)
- fprintf(file,"%d\n", i);
- }
- fclose(file);
- return 0;
- }
- int main()
- {
- int iww = 0, od = 0, pdo = 0, r = 0, tmp = 0, tod = 0, tpdo = 0;
- std::cin >> iww;
- std::cin >> od;
- std::cin >> pdo;
- HANDLE *h = new HANDLE[iww];
- DWORD *TID = new DWORD[iww];
- Date *dd = new Date[iww];
- tmp = (pdo - od) / iww;
- r = tmp;
- tod = od;
- for (int i = 0; i < iww; i++)
- {
- if (tmp >= pdo) tmp = pdo;
- char c = i + '0';
- dd[i] = {tod,r,c };
- h[i] = CreateThread(NULL, 0, Function, &dd[i], 0, &TID[i]);
- tod = r + 1;
- r = r + tmp;
- }
- WaitForMultipleObjects(iww, h, TRUE, INFINITE);
- for (int i = 0; i < iww; i++)
- {
- char filen[10];
- sprintf(filen, "%d.txt", i);
- FILE * file = fopen(filen,"r");
- while (!feof(file))
- {
- int s = 0;
- fscanf(file, "%d", &s);
- if(s != 0) cout << s << "\n";
- }
- fclose(file);
- }
- delete[] h;
- delete[] TID;
- delete[] dd;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement