parallel-programming/1/system/windows/ParallelNumber2.cpp

77 lines
2.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ParallelNumber2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <vector>
int begin, end, filey;
//std::string file_num;
std::string str;
std::string path = "C:\\Dod\\";
std::vector<int> primes;
bool isPrime(int num) {
if (num <= 1) {
return false;
}
for (int p : primes) {
if (num % p == 0) {
return false;
}
}
return true;
}
int main(int argc, char* argv[]) {
std::string numbersWithFiveDivisors;
begin = std::atoi(argv[1]);
end = std::atoi(argv[2]);
filey = std::atoi(argv[3]);
for (int num = 2; num <= 177; num++) {
if (isPrime(num)) {
primes.push_back(num);
}
}
for (int i = 0; i < primes.size(); i++) {
if (pow(primes[i], 4) > begin && pow(primes[i], 4) < end) {
numbersWithFiveDivisors += std::to_string(pow(primes[i], 4)) + " \n";
}
}
path += std::to_string(filey) + ".txt";
std::ofstream fout;
fout.open(path);
if (fout.is_open()) {
fout << numbersWithFiveDivisors << std::endl;
fout.close();
}
std::cout << "Numbers with three divisors: \n" << numbersWithFiveDivisors << std::endl;
system("pause");
return 0;
}
// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
// Советы по началу работы
// 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
// 2. В окне Team Explorer можно подключиться к системе управления версиями.
// 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
// 4. В окне "Список ошибок" можно просматривать ошибки.
// 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
// 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.