I have the next problem:
Joe likes numbers. His new concern is finding how many 0 (number) does the product of a range of integers have. He discovered that when the numbers grow up, they are harder to get him to the result. Joe needs your help.
Request:
We know the range of the closed interval. Show how many 0 numbers does the product contain. (The product of all the integers in that range)
Input:
In file zero.in we have on the 1st line, separated by space, two integers a and b, representing the range head/end. [a;b]
Output:
In file zero.out the program has to print a value representing the number of 0 (numbers) which the integers product has.
Restrictions and Specifications:
1 <= a <= b <= 2000000000
30% of the tests done to the .cpp file will have b-a <= 100000
Exemple:
zero.in : 4 11
zero.out: 2
Because the [4;11] range has the integers product (4*5*6*7*8*9*10*11) equal to 6652800 , from where we can see the 0 (number) twice.
zero.in : 134 5435435
zero.out: 1358821
Maximum execution time per test: 0.1 seconds.
Memory limit: 5 MB.
Source maximum memory: 5 KB.
---------------------------------------------
I have done the program, and it worked for example 1. All my tests worked for b-a <= 100. I couldnt get the program work with higher numbers than 164728561229104880924. (21 digits but I need to be able to work with over 100 digits)
P.S.1: I have been using unsigned long long.
P.S.2: Sorry for not very good translation of the problem.
I have found an algorithm on the internet, but I have no idea on how to use it ...
1 2 3 4 5 6 7 8 9 10 11 12
|
void mul(int A[], int B[])
{
int i, j, t, C[DIGIT_NUMBER];
memset(C, 0, sizeof(C));
for (i = 1; i <= A[0]; i++)
{
for (t=0, j=1; j <= B[0] || t; j++, t/=10)
C[i+j-1]=(t+=C[i+j-1]+A[i]*B[j])%10;
if (i + j - 2 > C[0]) C[0] = i + j - 2;
}
memcpy(A, C, sizeof(C));
}
|
ps3. im 9th grade .... 1st year studing officially C++....