重复和倒数
Reptends and Reciprocals

原始链接: https://www.gregegan.net/SCIENCE/Reptends/Reptends.html

格雷格·伊根的文章探讨了一个有趣的问题:在哪些进制下,一个整数的倒数可以拥有一个包含从0到该进制减1的所有数字(全数字)且不重复的重复数字块(循环节)? 文章证明了奇数进制不允许出现这种情况,并用模算术给出了形式证明。虽然计算机搜索发现了一些存在解的偶数进制(例如10、12、14),但确定这些进制的普遍规律仍然难以捉摸。计算也排除了8、16、32和64进制。 文章还深入探讨了有理数和重复数字之间的联系。文章给出了一个公式,用于根据任何进制下的前缀和重复数字来计算有理数。然后,它考察了用于生成倒数十进制表示的长除法过程,将其与模算术以及环和群Zn和Zn×的代数结构联系起来。最后,文章表明,如果进制和除数有公因子,可以将问题简化为寻找一个与进制互质的分母的分数的表示。

Hacker News 的一个评论线程讨论了美国的长除法记法,用户 Joker_vD 批评其布局不自然。他们认为被除数和除数顺序颠倒,以及答案写在顶部,不必要地增加了这个本来就对学生来说很困难的算法的难度。Joker_vD 建议使用更直观的记法,其中除数位于被除数的右侧,商写在右侧。他们将美国的方法与“竖式除法”进行对比,暗示了美国方法的复杂性。用户 nh23423fefe 回应道,为美国记法辩护,解释说它有助于零的扩展,并能轻松显示商的小数位。他们还对“自然顺序”的概念提出了质疑,指出“除”谓词中的顺序也是“相反的”。
相关文章
  • (评论) 2024-08-15
  • 用四个2s制作任何整数 2025-02-25
  • 评论 2023-10-13
  • 挑战 2023-11-16
  • (评论) 2025-03-20

  • 原文
    Reptends and Reciprocals — Greg Egan

    by Greg Egan


    Is there an integer d whose reciprocal, 1/d, has a decimal representation with a recurring block of digits exactly 10 digits long, containing all ten decimal digits?

    The answer is yes! 72,728 has this property. In fact, we can find integers with analogous properties in several different bases besides base 10. A number is described as pandigital in base b if its representation contains all the digits 0, ..., b – 1, and non-redundant if each digit appears only once, so we will call these blocks of b repeating digits, enclosed in parentheses in the table below, non-redundant pandigital reptends.

    Smallest integers whose reciprocals have non-redundant pandigital reptends
    Base 21/3=0.(01)2 ...
    Base 41/34=0.0(0132)4 ...
    Base 61/93=0.0(021534)6 ...
    Base 101/72,728=0.000(0137498625) ...
    Base 121/12,560=0.00(01798A2654B3)12 ...
    Base 141/28,784,914,432=0.000000000A09(7DAC59B6031842)14 ...
    Base 181/82,703,547,776=0.0000000(02731C6D8HFAEG5B49)18 ...
    Base 201/2,188,281,250=0.0000000B(DJ98CIF5HG60AB714E23)20 ...
    Base 241/858,884,438,628,757,833,498,003,410,317,638=0.000000000000000000000001D6AKMNILGKDHL265F1KJAIMFAM0(MF0B1CJD274EHGN56AKIL938)24 ...
    Base 301/17,344=0.001GL1(ONRA8PKEBM0QH1D562JL49FI7T3CSG)30 ...

    Here we are describing the integers themselves with the usual base 10 notation, and only switching to base b when we give the representations of the fractions. We follow the convention of using the letters A, B, C, ... for digits 10, 11, 12, ... in bases greater than 10.

    These numbers were found with a computer search, which came up empty for all the other bases that were tried. But are these really the only bases in which an integer can have this property?

    Question: In what bases can the reciprocal of an integer have a non-redundant pandigital reptend?

    Partial answer: We will prove with some simple number theory that there are no solutions for odd bases, and computer calculations have ruled out solutions for bases 8, 16, 32 and 64. But in general, this is still an open question.

    [If we didn’t care about the non-redundancy of the digits, this would be a trivial question: for every base there are an infinite number of integers whose reciprocals have pandigital reptends, when some digits are allowed to appear more than once. The Online Encyclopedia of Integer Sequences has a list of the smallest such integers for each base, A382498.]


    From Repeating Digits to Rational Numbers

    One step towards answering this question is to look at the rational number we get if we are provided with the representation of a number in base b in the following form:

    0 . k-digit prefix x j-digit reptend r j-digit reptend r ...

    Here k, the length of the non-repeating portion of the number, can be zero, but we will assume that j, the length of the reptend, is at least 1. By x and r we mean the integers whose digits slot into this pattern, with 0 ≤ x < bk and 0 ≤ r < bj.

    The rational number R that this represents can be found by summing a geometric series with an infinite number of terms:

    R = [x + r Σi = 1 (1 / bj)i] / bk
    = [x + (r / bj) 1 / (1 – 1 / bj)] / bk
    = [x + r / (bj – 1)] / bk

    We can check this formula with a few examples:

    R = 0.(142857) ...
    b = 10
    r = 142,857
    j = 6
    x = k = 0

    R = 142,857 / (106 – 1) = 142,857 / 999,999 = 1/7

    R = 0.03(571428) ...
    b = 10
    r = 571,428
    j = 6
    x = 3
    k = 2

    R = (3 + 571,428 / (106 – 1)) / 102
    = (3 + 571,428 / 999,999) / 100
    = (3 + 4/7) / 100
    = 25/700
    = 1/28

    R = 0.0(0132)4 ...
    b = 4
    r = 1324 = 2 + 3×4 + 1×42 = 30
    j = 4
    x = 0
    k = 1

    R = (30 / (44 – 1)) / 4
    = (30 / 255) / 4
    = 1/34

    Since we will mostly be concerned with rational numbers that are reciprocals of integers, we will find it useful to rewrite this formula as:

    When R = 1/d:

    d [r + x (bj – 1)] = (bj – 1) bk

    Excluding the Odd Bases

    Let’s return to our original question about which bases allow reciprocals of integers to have non-redundant pandigital reptends. We will be performing several calculations in modular arithmetic, with modulus b – 1. We start with a couple of obvious statements:

    b ≡ 1 (mod b – 1)
    bi ≡ 1 (mod b – 1) for any integer i

    This in turn means that any number with digits Di is equivalent, mod b – 1, to the sum of its digits:

    Σi=0n Di bi ≡ Σi=0n Di (mod b – 1)

    This is the basis for the well-known divisibility tests for 3 and 9: a number in base 10 will be equivalent to the sum of its digits, modulo 9.

    For a non-redundant pandigital integer Pb in base b, since its digits are 0, ..., b – 1 (in any order, it doesn’t matter), we have:

    Pb ≡ Σi=0b – 1 i ≡ ½ b (b – 1) (mod b – 1)

    Now, suppose the base b is odd. Then b – 1 is even, and we have:

    Pb ≡ ½(b – 1) (mod b – 1, for b odd)

    For example, if b = 7, then for any non-redundant pandigital number in base 7, with 0+1+2+3+4+5+6 = 21:

    P7 ≡ ½(b – 1) ≡ 3 (mod 6)

    If we take our formula linking an integer d with the features of its reciprocal’s representation in base b, and assume that the reptend r is a non-redundant pandigital number in an odd base, we get:

    For odd base b, and a non-redundant pandigital reptend r for the reciprocal of d:

    r ≡ ½(b – 1) (mod b – 1)

    d [r + x (bb – 1)] = (bb – 1) bk
    d r = (bb – 1) (bkd x)
    d r = (b – 1) (1 + b + b2 + ... + bb – 1) (bkd x)

    The reptend r is not divisible by b – 1, so d must be. Suppose d = g (b – 1), and divide both sides of the equation by b – 1.

    g r = (1 + b + b2 + ... + bb – 1) (bkg (b – 1) x)

    Now taking everything mod b – 1:

    g (½(b – 1)) ≡ (1 + 1 + ... [b terms]) (1 – 0) ≡ 1 (mod b – 1)

    If g is even, then g (½(b – 1)) ≡ 0 (mod b – 1), so g must be odd. But in that case, g (½(b – 1)) ≡ ½(b – 1), leaving us with:

    ½(b – 1) = 1
    b = 3

    So we have ruled out all odd bases except for b = 3. But our computer search found no reciprocals with non-redundant pandigital reptends in base 3. Can we prove that this is also impossible?

    The non-redundant pandigital integers in base 3 are:

    {0123, 0213, 1023, 1203, 2013, 2103}
    = {5, 7, 11, 15, 19, 21}

    Note that all of these values are odd.

    Our formula linking the integer d with the representation of its reciprocal becomes:

    d [r + x (bb – 1)] = (bb – 1) bk
    d [r + 26 x] = 26 × 3k = 2 × 13 × 3k

    Since r must be odd, the only possible prime factors of r + 26 x are 3 and 13. If we first assume no factor of 13, we have:

    r + 26 xr ≡ 3a (mod 13)

    But since 33 = 27 ≡ 1 (mod 13), the only powers of 3 are {1, 3, 9} (mod 13), whereas our list of possible values of r is:

    {5, 7, 11, 15, 19, 21} ≡ {5, 7, 11, 2, 6, 8} (mod 13)

    On the other hand, if we assume r + 26 x does have a factor of 13, then so will r. But none of the possible values of r satisfies this condition either.

    So we have proved:

    Theorem 1: In any odd base, no integer has a reciprocal with a non-redundant pandigital reptend.

    Even Bases

    Now, suppose the base b is even. We then have, for any non-redundant pandigital integer:

    Pb ≡ ½ b (b – 1) ≡ 0 (mod b – 1, b even)

    For example, if b = 10, then for any non-redundant pandigital number in base 10, with 0+1+2+3+4+5+6+7+8+9 = 45:

    P10 ≡ 0 (mod 9)

    If our reptend r is a non-redundant pandigital integer, we have:

    For even base b, and a non-redundant pandigital reptend r for the reciprocal of d:

    r = (b – 1) s, for some integer s

    (bb – 1) = (b – 1) (1 + b + b2 + ... + bb – 1)
          = (b – 1) (b + 1) (1 + b2 + b4 + ... + bb – 2)

    d [r + x (bb – 1)] = (bb – 1) bk

    To conduct a computer search for solutions for a fixed choice of b and k, we can factor the right-hand side of the last equation above, (bb – 1) bk into individual prime factors, which must then be allocated between the two algebraic factors on the left-hand side, d and [r + x (bb – 1)]. This lets us enumerate all the possible values for [r + x (bb – 1)], and we can extract r alone by taking that quantity and computing the remainder mod (bb – 1). If none of the resulting values for r are non-redundant pandigital integers in base b, that means there are no solutions for our choice of b and k.

    For bases 8, 16, 32 and 64, for all choices of divisors of bb – 1 the values of r were seen to cycle under multiplication by 2 (mod bb – 1), making it unnecessary to check any higher values of k. So these bases have been proved not to have any solutions. When b = 2t, we have bb = 2t 2t, and multiplying any number by 2 at most t 2t times will cycle back to the original value (mod bb – 1).

    If we assumed that the possible values of r were spread uniformly at random among the b-digit integers, then the maximum probability that at least one of them would be among the b! pandigital numbers is given by the rightmost column in the table below. That there is actually no solution for b = 8 suggests the probabilities here are an overestimate. But it any case, this makes it intuitively reasonable that there are no solutions for higher powers of 2.

    t b t 2t Divisors of bb – 1 # of r values
    (at most)
    bb b! Probability of at least
    one r in b!/bb =
    1 – (1 – b!/bb)#r
    12224420.9375
    248864256240.998164
    3824962,30416,777,21640,3200.996088
    416641288,1921.84 × 10192.09 × 10130.00924856
    5321606,144983,0401.46 × 10482.63 × 10351.77 × 10–7
    664384786,432301,989,8883.94 × 101151.27 × 10899.725 × 10–19

    However, for an arbitrary base there is no obvious ceiling on the values of k that might need to be examined [other than bb – 1, which is too large to be practical for most bases], so without further theoretical justification, we can’t claim to have ruled out solutions for any other even base.

    From Reciprocals to Repeating Digits

    The Long Division Algorithm

    Let’s take a look at the reverse of the process we considered in the previous section. Given a reciprocal of an integer, 1/d, what is the prefix x of length k and reptend r of length j that are produced in base b?

    Of course the algorithm that produces these things is just long division, but because most people learn how to do this at a very young age and never revisit it, a lot of the richness and subtlety of the underlying mathematics passes us by.

    Let’s examine what happens when we use long division to find the decimal representations of 1/13 and 1/28.

    0.076923... 13 | 1.000000000 –0 (0 × 13) 100 –91 (7 × 13) 90 –78 (6 × 13) 120 –117 (9 × 13) 30 –26 (2 × 13) 40 –39 (3 × 13) 10
    0.03571428... 28 | 1.000000000 –0 (0 × 28) 100 –84 (3 × 28) 160 –140 (5 × 28) 200 –196 (7 × 28) 40 –28 (1 × 28) 120 –112 (4 × 28) 80 –56 (2 × 28) 240 –224 (8 × 28) 160

    Starting with the number 1, we multiply the current remainder by 10, find the largest multiple of the divisor, d, that it contains, record the multiplier as the digit in the quotient, then continue with the new remainder we obtain by subtracting that multiple of d.

    For d=28, because we return to a remainder of 16, rather than 1, the digits do not repeat from the start; the digits 03 form a non-repeating prefix, while 571428 is the reptend.

    The remainders here are just the powers of the base, 10, modulo the divisor.

    1001
    10110 = 0 × 13 + 10
    102100 = 7 × 13 + 9
    10390 = 6 × 13 + 12
    104120 = 9 × 13 + 3
    10530 = 2 × 13 + 4
    10640 = 3 × 13 + 1
    1001
    10110 = 0 × 28 + 10
    102100 = 3 × 28 + 16
    103160 = 5 × 28 + 20
    104200 = 7 × 28 + 4
    10540 = 1 × 28 + 12
    106120 = 4 × 28 + 8
    10780 = 2 × 28 + 24
    108240 = 8 × 28 + 16

    The Ring Zn and the Group Zn×

    To understand the kinds of sequences that the powers of a base, b, can produce modulo the divisor, d, we need to delve a little further into the algebraic structure that underlies modular arithmetic.

    When we are performing modular arithmetic on the n integers 0, 1, ..., n–1, we refer to this set as Zn. If we are only interested in addition, Zn becomes what is known as a commutative group: a set with a single operation, +, that obeys all the usual rules for adding numbers, including the existence of an additive identity, 0, which leaves things unchanged when you add it, and additive inverses for every number x in the set, which you can add to x to get 0. In this case, we have:

    x + (nx) ≡ 0 (mod n)

    If we also wish to perform multiplication, things become a bit more complicated. When we deal with the set of all integers, Z, we are already used to the fact that although there is a multiplicative identity, 1, which leaves things unchanged when you multiply with it, unlike the real numbers and the rational numbers, in the integers most numbers do not have a multiplicative inverse. The only integers with multiplicative inverses are 1 and –1, whereas every real number other than zero has a multiplicative inverse.

    For Zn, the situation can lie anywhere between these two extremes. If n is a prime number, then every number in Zn other than zero does have a multiplicative inverse. For example, in Z7:

    1 × 1 ≡ 1 (mod 7)
    2 × 4 ≡ 1 (mod 7)
    3 × 5 ≡ 1 (mod 7)

    But if n is not prime, then only those numbers that have no factor greater than 1 in common with n have multiplicative inverses. For example, in Z8:

    1 × 1 ≡ 1 (mod 8)
    3 × 3 ≡ 1 (mod 8)
    5 × 5 ≡ 1 (mod 8)
    7 × 7 ≡ 1 (mod 8)
    But 2, 4, 6 have no multiplicative inverses.

    It is not hard to see why a number that has a factor f greater than 1 in common with n cannot have a multiplicative inverse in Zn. If x is divisible by f then any multiple of x, say mx, will also be divisible by f, even when the product is greater than or equal to n and we subtract a multiple of n to keep the result in Zn. But 1 plus any multiple of n is obviously not divisible by f, so mx can never be equivalent to 1.

    Now, consider the subset of Zn consisting of all elements that do not have any factor greater than 1 in common with n. We will call this Zn×.

    Clearly 1 is in Zn×. If x and y are both in Zn×, can xy have a factor greater than 1 in common with n, say f? If it did, then any prime factor p of f would need to divide at least one of x and y, and would also divide n, contradicting our assumption. So, xy will also be in Zn×.

    Furthermore, suppose x, y and z are all in Zn×, and xyxz (mod n). It follows that:

    x (yz) ≡ 0 (mod n)

    In other words, n divides x (yz). But since x and n have no factors greater than 1 in common, n must divide yz. So we can conclude that:

    For x, y and z in Zn×
    xyxz (mod n) if and only if yz (mod n)

    It then follows that if we multiply every element of Zn× by some x in Zn×, the products must all be distinct, and must be all the elements of Zn× itself, including 1. Since one of the products is 1, whatever we multiplied by x to produce 1 will be the unique multiplicative inverse of x.

    Taken together, all the properties we have established for Zn× (along with the obvious fact that multiplication is associative) make it a commutative group, known as the multiplicative group of integers modulo n.

    If n is prime, Zn× contains all the non-zero elements of Zn, so every non-zero element of Zn has a multiplicative inverse, as we claimed earlier. This means Zn is an algebraic structure known as a field, like the real numbers.

    When n is not prime, Zn is a commutative ring with unity, which is the same kind of structure as the set of all integers, Z.

    When n is prime, the size of Zn×, which we will write as |Zn×|, is just n–1. But in general, |Zn×| is given by Euler’s totient function, φ(n), which counts the numbers less than n that are relatively prime to n (which is just another way of saying that they share no factor with n greater than 1). Euler’s totient function can be evaluated directly, without checking all the numbers for this property individually, with the formula:

    φ(n) = n ΠDistinct primes p that divide n (1 – 1/p)

    Here Π is the symbol for a product, i.e. we are multiplying together the expression that follows, for each distinct prime p that divides n.

    It was proved by Gauss that if and only if n is 1, 2, 4, pk or 2 pk, for p an odd prime, Zn× is a cyclic group, i.e. a group where every element is some integer power of a single element, known as the generator of the group.

    Base and Divisor Relatively Prime

    Suppose we compute the digits in the base b representation of the reciprocal of some integer d that is relatively prime to b, i.e. they share no common factors greater than 1. Then b will belong to the group Zd×, as will all its integer powers. For example, if d=13 and b=10, as we saw earlier the powers of 10 (mod 13), starting from 100, are {1, 10, 9, 12, 3, 4}. Note that in this case, since d is prime, we know immediately that |Zd×|=12, and it is no coincidence that the size of the set of powers of 10, which is 6, divides |Zd×|. The powers of 10 (mod 13) form a subgroup of the group Zd×, and the number of elements of any subgroup of a group must divide the number of elements of the group. In general, if d is relatively prime to b, the length of the reptend of 1/d must divide |Zd×| = φ(d).

    Given the powers of 10 (mod 13), and knowing the representation for 1/13 in base 10, we can immediately write down the representations for six different fractions with 13 in the denominator. We just take the successive powers of 10 (mod 13) as the numerators, and rotate the digits in the reptend:

    1/13=0.(076923) ...
    10/13=0.(769230) ...
    9/13=0.(692307) ...
    12/13=0.(923076) ...
    3/13=0.(230769) ...
    4/13=0.(307692) ...

    We can obtain the representations of the remaining six fractions by doubling the powers of 10 (mod 13) we use as the numerators:

    2 &times {1, 10, 9, 12, 3, 4} ≡ {2, 7, 5, 11, 6, 8} (mod 13)

    and doubling the reptend for 1/13 to obtain the six digits for 2/13, then rotating them as before:

    2/13=0.(153846) ...
    7/13=0.(538461) ...
    5/13=0.(384615) ...
    11/13=0.(846153) ...
    6/13=0.(461538) ...
    8/13=0.(615384) ...

    In general, if d is relatively prime to b, then the powers of b will form a subgroup of Zd×, the subgroup generated by b, which can be written more succinctly as <b>. The size of <b> is called the multiplicative order of b modulo d. Either this subgroup <b> will be the entire group Zd×, and all fractions less than 1 with d in the denominator when written in lowest terms can be found by cycling the digits of the reptend, or it will comprise some smaller portion of Zd×, and the other fractions can be found by taking suitable multiples of <b>, producing reptends with different digits but the same length.

    If d is prime, that will cover all the fractions 1/d, 2/d, ..., (d–1)/d. If d is composite, there will be some numerators in that list that are not relatively prime to d (and hence not in Zd×), so d will no longer be the denominator when the fraction is written in lowest terms. For those cases, the representation can be found by examining the numerator and denominator after cancelling any common factors.

    Base and Divisor Have Common Factors

    If the base b and the divisor d have any common factors, we can list all the primes that divide both b and d, and call them p1, ..., pm. Define:

    h = p1k1 × ... × pmkm

    where each ki is the maximum power of pi that divides d. It follows that d/h will be an integer with no factors greater than 1 in common with b.

    Similarly, define qi as the maximum power of pi that divides b. Then define K as the maximum of all the integers ceiling(ki / qi), for i = 1, ..., m. Then for each i, the factor of pi in bK will be greater than or equal to ki, and so bK will be divisible by h.

    We can then write:

    1/d = (1/bK) [(bK/h) / (d/h)]

    where the numerator and denominator of the fraction in the square brackets are both integers, and the denominator is relatively prime to b.

    For example, if b = 10 and d = 28, they only have a single prime factor in common:

    p1 = 2
    k1 = 2
    h = p1k1 = 4
    q1 = 1
    ceiling(k1 / q1) = 2
    K = 2

    1/28 = (1/102) [(102/4) / (28/4)]
    = (1/102) [25 / 7]
    = (1/100) [3 + 4/7]
    = 0.03(571428) ...

    So we have reduced the problem of finding the representation of 1/28 to one of finding the representation of 4/7, with a denominator relatively prime to the base, shifted right by two places, with a prefix of 0.03 before it.



    Science Notes / Reptends and Reciprocals / created Saturday, 19 April 2025
    联系我们 contact @ memedata.com