A friend of mine is interviewing for a job. One of the interview questions got me thinking, just wanted some feedback.
There are 2 non-negative integers: i and j. Gi
Why not try looking at this from the other direction. Use a counter to test the possible answers against the original formula. Sorry for the pseudo code.
for x = 1 to n
{
i=j=0
y=x
while ( y > 1 )
{
z=y
if y divisible by 2 then increment i and divide y by 2
if y divisible by 5 then increment j and divide y by 5
if y=1 then print i,j & x // done calculating for this x
if z=y then exit while loop // didn't divide anything this loop and this x is no good
}
}