You’re given array D of size N and Q queries X. In each query you have to compute the result of the program
read X for i = 1..N: X = floor(X / D*) print X
You should consider only O(\log X) terms such that D_i eq 1.
You may keep keep first \min(2\cdot\log_2 X, N) terms of D which aren’t equal one. If there are more non-one terms than X wiil definitely be equal zero at the end of procedure.
You can keep product P of non-one terms of D instead of keeping this terms and divide X by P. But you should check then that you output zero if there are too much such terms.