3. Repetend

l  Problem

Repetend is the infinite repeating figures in a repeating decimal. Every repeating decimal can be expressed as a fraction. So as long as a fraction is given, one can calculate its repetend. Please develop a program to implement this algorithm.


l  Tip

General steps: Get the remainder of the dividend in division by the divisor, and judge whether the remainder appeared in the previous computation. If it has not appeared yet, then multiply the remainder by 10 and take the result as the dividend. Continue the loop and repeat the computation to calculate the remainder until a same remainder that has once appeared is found.  The quotient between the position where the same remainder appears last time and the position where it appears this time is the repetend in the repeating decimal.

1.  Get the remainder by dividing the dividend by the divisor.

2.  Firstly judge in the loop body whether the remainder appeared in the preceding computation. If it did, then suspend the loop.

3.  If the remainder has not appeared, add the current remainder to historical remainder sequence, and then multiply the current remainder by 10 and take the result as the dividend to be divided by the divisor. Add the quotient into the historical quotient sequence, replace the current remainder with the resulting remainder, and enter the next round of loop.

4.  According to the digits from the position where the current remainder is found in the historical remainders to the position of the last remainder, find the quotients at the corresponding positions in the historical quotient sequence. This group of quotients is the repetend.


l  Code

















Obtain the remainder




Define the infinite loop. If the remainder obtained in this loop has appeared in the remainders in previous loops, then end the loop, and B4 stores the position in which the remainder appears.



if B4>0







Store the remainder computed each time.





Store the quotient computed each time.





Refresh A3 to appear as the current remainder.




In B7, part from position B4 to the last number is the repetends. Take out the repetends and put them into string.


l  Result