I had a question for the following problem (FCTRL from Codechef)
I am trying to enter in an arraysize. I am then trying to test each number in the array. The test for each number in the array is how many powers of 5 go into to it.
i.e if the number is 4617;
5^1 : 4617 ÷ 5 = 923.4, so 923 factors of 5
5^2 : 4617 ÷ 25 = 184.68, so 184 additional factors of 5
5^3 : 4617 ÷ 125 = 36.936, so 36 additional factors of 5
5^4 : 4617 ÷ 625 = 7.3872, get 7 additional factors of 5
5^5 : 4617 ÷ 3125 = 1.47744, so 1 more factor of 5
5^6 : 4617 ÷ 15625 = 0.295488, which is less than 1, so stop.
I then wish to add these up. However, ruing for an array size of 1, and the test number 1024, I get 245, when the answer is 253.
Any help is appreciated.
#include <iostream>
using namespace std;
int main()
{
int arraySize;
int answer;
cin >> arraySize;
int arr[arraySize];
for (int i = 0; i < arraySize; i++ ){
int number;
cin >> number;
arr[i] = number;
}
for (int j = 0; j < arraySize; j++){
int sum = 0;
int divisor = 5;
while ( (arr[j]/divisor) > 0 ){
sum += (arr[j]/divisor);
divisor = divisor * divisor;
}
cout << sum << endl;
}
retu 0;
}
