UVa 12414 - Calculating Yuan Fen

Please refer to this site for a simulation and an explanation of a plausible solution.