Algorithm for detecting repeating decimals?

前端 未结 6 1965
悲&欢浪女
悲&欢浪女 2020-12-10 05:23

Is there an algorithm for figuring out the following things?

  1. If the result of a division is a repeating decimal (in binary).
  2. If it repeats, at what di
6条回答
  •  自闭症患者
    2020-12-10 06:04

    1. if the divisor is not a power of 2 (in general, contains prime factors not shared with the base of representation)
    2. repeat cycle length will be driven by the largest prime factor of the dividend (but not connected with the length of the representation of that factor -- see 1/7 in decimal), but the first cycle length may differ from the repeat unit (e.g. 11/28 = 1/4+1/7 in decimal).
    3. the actual cycle will depend on the numerator.

提交回复
热议问题