58 lines
1.1 KiB
C++
58 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include <cmath>
|
|
#include <fstream>
|
|
#include <vector>
|
|
#include <stdlib.h>
|
|
|
|
int begin, end, filey;
|
|
|
|
|
|
std::string str;
|
|
std::string path = "/home/danila/systemVZ/Dod/";
|
|
|
|
|
|
bool hasFiveDivisors(int num) {
|
|
int count = 0;
|
|
for (int i = 1; i <= sqrt(num); i++) {
|
|
if (num % i == 0) {
|
|
count++;
|
|
if (num / i != i) {
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
return count == 5;
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
std::string numbersWithFiveDivisors;
|
|
int count = 0;
|
|
|
|
begin = std::atoi(argv[1]);
|
|
|
|
end = std::atoi(argv[2]);
|
|
|
|
filey = std::atoi(argv[3]);
|
|
for (int num = begin; num <= end; num++) {
|
|
if (hasFiveDivisors(num)) {
|
|
numbersWithFiveDivisors += std::to_string(num) + " ";
|
|
count++;
|
|
}
|
|
}
|
|
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: " << numbersWithFiveDivisors << std::endl;
|
|
std::cout << "Total count: " << count << std::endl;
|
|
|
|
return 0;
|
|
} |