There are 1000 numbers in number.txt, from 2 to 9 digits, each on a separate line. The exercise is to count the number of numbers that fill the condition: when factorizing, this number has exactly 3 different simple factors, they can occur several times, and all of them are even numbers.
for example
105 - factors: 3, 5, 7 - YES,
1287 - factors: 3, 3, 11, 13 - YES,
1157625 - factors: 3,3,3,5,5,5,7,7,7 - YES,
55 - factors: 5, 11 - NO.
#include <iostream>
#include <fstream>
using namespace std;
int number, threefnumbers=0;
int main()
{
ifstream file("numbers.txt");
ofstream outputf("results.txt");
int count_factors;
while (file >> number)
{
count_factors=0;
int factor=3;
if (number%2!=0)
{
while (number>1)
{
if (number%factor==0)
count_factors++;
while (number%factor==0)
{
number=number/factor;
}
factor+=2;
}
if (count_factors==3) threefnumbers++;
}
}
outputf << "59.1) " << endl << threefnumbers;
file.close();
outputf.close();
return 0;
}
I know from number.txt that there are many numbers that fulfill the condition, but the program returns only 1. Why is this?