How to Read Set a Repeating Decmel in C++

Decimal representation of a number whose digits are periodic

A repeating decimal or recurring decimal is decimal representation of a number whose digits are periodic (repeating its values at regular intervals) and the infinitely repeated portion is not null. It can be shown that a number is rational if and simply if its decimal representation is repeating or terminating (i.due east. all except finitely many digits are zero). For case, the decimal representation of i / iii becomes periodic just subsequently the decimal point, repeating the single digit "three" forever, i.east. 0.333.... A more than complicated example is 3227 / 555 , whose decimal becomes periodic at the 2nd digit post-obit the decimal point and then repeats the sequence "144" forever, i.due east. 5.8144144144.... At present, there is no single universally accepted annotation or phrasing for repeating decimals.

The infinitely repeated digit sequence is called the repetend or reptend. If the repetend is a nada, this decimal representation is called a terminating decimal rather than a repeating decimal, since the zeros can be omitted and the decimal terminates before these zeros.[one] Every terminating decimal representation can be written as a decimal fraction, a fraction whose denominator is a ability of 10 (e.grand. 1.585 = 1585 / grand ); it may also be written every bit a ratio of the form k / two n 5 m (east.g. 1.585 = 317 / ii352 ). Even so, every number with a terminating decimal representation besides trivially has a second, alternative representation as a repeating decimal whose repetend is the digit 9. This is obtained by decreasing the final (rightmost) non-zero digit past ane and appending a repetend of 9. 1.000... = 0.999... and ane.585000... = 1.584999... are 2 examples of this. (This type of repeating decimal tin can be obtained by long sectionalization if one uses a modified form of the usual division algorithm.[two])

Any number that cannot be expressed as a ratio of two integers is said to be irrational. Their decimal representation neither terminates nor infinitely repeats but extends forever without regular repetition. Examples of such irrational numbers are 2 and π.

Groundwork [edit]

Annotation [edit]

There are several notational conventions for representing repeating decimals. None of them are accepted universally.

  • In the United States, Canada, India, France, Frg, Switzerland, Czechia, and Slovakia the convention is to draw a horizontal line (a vinculum) above the repetend. (Run into examples in table below, column Vinculum.)
  • In the United kingdom of great britain and northern ireland, New Zealand, Australia, Bharat, Republic of korea, and mainland Prc, the convention is to identify dots above the outermost numerals of the repetend. (See examples in table below, column Dots.)
  • In parts of Europe, Vietnam and Russia, the convention is to enclose the repetend in parentheses. (See examples in table beneath, column Parentheses.) This tin can cause confusion with the notation for standard uncertainty.
  • In Espana and some Latin American countries, the arc notation over the repetend is also used as an alternative to the vinculum and the dots notation. (See examples in table below, column Arc.)
  • Informally, repeating decimals are often represented past an ellipsis (three periods, 0.333...), especially when the previous notational conventions are first taught in schoolhouse. This notation introduces uncertainty as to which digits should exist repeated and even whether repetition is occurring at all, since such ellipses are also employed for irrational numbers; π, for example, can be represented as iii.14159....
Examples
Fraction Vinculum Dots Parentheses Arc Ellipsis
1 / nine 0.1 0. 1 ˙ {\displaystyle 0.{\dot {one}}} 0.(1) 0.ane 0.111...
1 / iii = 3 / 9 0.3 0. three ˙ {\displaystyle 0.{\dot {3}}} 0.(3) 0.3 0.333...
2 / iii = 6 / ix 0.6 0. vi ˙ {\displaystyle 0.{\dot {6}}} 0.(half dozen) 0.half-dozen 0.666...
9 / 11 = 81 / 99 0.81 0. 8 ˙ one ˙ {\displaystyle 0.{\dot {8}}{\dot {1}}} 0.(81) 0.81 0.8181...
7 / 12 = 525 / 900 0.58three 0.58 3 ˙ {\displaystyle 0.58{\dot {3}}} 0.58(3) 0.583 0.58333 ...
i / 7 = 142857 / 999999 0.142857 0. ane ˙ 4285 7 ˙ {\displaystyle 0.{\dot {ane}}4285{\dot {7}}} 0.(142857) 0.142857 0.142857142857 ...
1 / 81 = 12345679 / 999999999 0.012345679 0. 0 ˙ 1234567 9 ˙ {\displaystyle 0.{\dot {0}}1234567{\dot {ix}}} 0.(012345679) 0.012345679 0.012345679012345679 ...
22 / 7 = 3142854 / 999999 three.142857 three. i ˙ 4285 vii ˙ {\displaystyle three.{\dot {ane}}4285{\dot {seven}}} three.(142857) three.142857 three.142857142857 ...

In English, at that place are various ways to read repeating decimals aloud. For instance, 1.two34 may exist read "one betoken two repeating three four", "one signal two repeated three four", "one point two recurring three four", "i point two repetend three four" or "one point ii into infinity 3 four".

Decimal expansion and recurrence sequence [edit]

In gild to convert a rational number represented as a fraction into decimal class, 1 may use long partition. For case, consider the rational number five / 74 :

                      0.0675                    74 ) v.00000          4.44          560          518          420          370          500        

etc. Notice that at each stride nosotros have a remainder; the successive remainders displayed above are 56, 42, 50. When nosotros arrive at 50 every bit the residuum, and bring down the "0", we find ourselves dividing 500 by 74, which is the same problem we began with. Therefore, the decimal repeats: 0.0675675 675 .....

Every rational number is either a terminating or repeating decimal [edit]

For whatsoever given divisor, only finitely many different remainders can occur. In the example above, the 74 possible remainders are 0, one, 2, ..., 73. If at whatever point in the division the remainder is 0, the expansion terminates at that point. And then the length of the repetend, also called "catamenia", is defined to be 0.

If 0 never occurs equally a remainder, and then the division process continues forever, and eventually, a remainder must occur that has occurred earlier. The side by side footstep in the sectionalization will yield the aforementioned new digit in the quotient, and the same new remainder, as the previous time the remainder was the same. Therefore, the following division volition repeat the same results. The repeating sequence of digits is called "repetend" which has a certain length greater than 0, likewise called "period".[three]

Every repeating or terminating decimal is a rational number [edit]

Each repeating decimal number satisfies a linear equation with integer coefficients, and its unique solution is a rational number. To illustrate the latter point, the number α = 5.8144144144... above satisfies the equation 10000α − 10α = 58144.144144... − 58.144144... = 58086, whose solution is α = 58086 / 9990 = 3227 / 555 . The process of how to notice these integer coefficients is described below.

Table of values [edit]

  • fraction

    decimal
    expansion
    10
    ane / 2 0.5 0
    1 / 3 0.3 one
    1 / 4 0.25 0
    1 / v 0.2 0
    one / 6 0.one6 1
    i / 7 0.142857 6
    1 / 8 0.125 0
    1 / 9 0.1 1
    1 / 10 0.1 0
    1 / 11 0.09 2
    one / 12 0.08iii 1
    1 / 13 0.076923 6
    1 / 14 0.0714285 half dozen
    i / 15 0.06 1
    1 / 16 0.0625 0
  • fraction

    decimal
    expansion
    x
    1 / 17 0.0588235294117647 16
    1 / 18 0.05 1
    1 / 19 0.052631578947368421 18
    1 / 20 0.05 0
    1 / 21 0.047619 six
    1 / 22 0.045 2
    ane / 23 0.0434782608695652173913 22
    1 / 24 0.041six 1
    1 / 25 0.04 0
    one / 26 0.0384615 6
    1 / 27 0.037 3
    1 / 28 0.03571428 half dozen
    1 / 29 0.0344827586206896551724137931 28
    1 / 30 0.03 1
    1 / 31 0.032258064516129 15
  • fraction

    decimal
    expansion
    10
    i / 32 0.03125 0
    1 / 33 0.03 2
    1 / 34 0.02941176470588235 16
    1 / 35 0.0285714 six
    1 / 36 0.027 i
    i / 37 0.027 3
    1 / 38 0.0263157894736842105 eighteen
    i / 39 0.025641 vi
    1 / twoscore 0.025 0
    1 / 41 0.02439 5
    1 / 42 0.0238095 half-dozen
    1 / 43 0.023255813953488372093 21
    1 / 44 0.0227 2
    1 / 45 0.02 1
    i / 46 0.02173913043478260869565 22

Thereby fraction is the unit fraction 1 / n and 10 is the length of the (decimal) repetend.

The lengths of the repetends of 1 / n , n = 1, 2, three, ..., are:

0, 0, 1, 0, 0, 1, vi, 0, 1, 0, two, 1, 6, half dozen, one, 0, 16, 1, 18, 0, 6, 2, 22, 1, 0, six, 3, half-dozen, 28, ane, 15, 0, two, 16, 6, 1, three, xviii, 6, 0, 5, half dozen, 21, 2, 1, 22, 46, 1, 42, 0, 16, 6, 13, 3, ii, 6, xviii, 28, 58, i, threescore, fifteen, 6, 0, half-dozen, two, 33, 16, 22, 6, 35, one, 8, iii, 1, ... (sequence A051626 in the OEIS).

The repetends of 1 / n , n = ane, 2, iii, ..., are:

0, 0, 3, 0, 0, 6, 142857, 0, 1, 0, 09, 3, 076923, 714285, 6, 0, 0588235294117647, five, 052631578947368421, 0, 047619, 45, 0434782608695652173913, 6, 0, 384615, 037, 571428, 0344827586206896551724137931, 3, ... (sequence A036275 in the OEIS).

The repetend lengths of 1 / p , p = 2, 3, five, ... (nth prime), are:

0, i, 0, half dozen, 2, 6, 16, eighteen, 22, 28, 15, iii, five, 21, 46, 13, 58, threescore, 33, 35, eight, 13, 41, 44, 96, 4, 34, 53, 108, 112, 42, 130, eight, 46, 148, 75, 78, 81, 166, 43, 178, 180, 95, 192, 98, 99, xxx, 222, 113, 228, 232, 7, 30, 50, 256, 262, 268, five, 69, 28, ... (sequence A002371 in the OEIS).

The to the lowest degree primes p for which one / p has repetend length n, north = 1, two, 3, ..., are:

iii, 11, 37, 101, 41, seven, 239, 73, 333667, 9091, 21649, 9901, 53, 909091, 31, 17, 2071723, 19, 1111111111111111111, 3541, 43, 23, 11111111111111111111111, 99990001, 21401, 859, 757, 29, 3191, 211, ... (sequence A007138 in the OEIS).

The least primes p for which k / p has n dissimilar cycles (1 ≤ kp−ane), n = 1, 2, three, ..., are:

7, three, 103, 53, 11, 79, 211, 41, 73, 281, 353, 37, 2393, 449, 3061, 1889, 137, 2467, 16189, 641, 3109, 4973, 11087, 1321, 101, 7151, 7669, 757, 38629, 1231, ... (sequence A054471 in the OEIS).

For comparison, the lengths of the repetends of the binary fractions one / northward , n = 1, 2, 3, ..., are:

ane, two, one, 4, ii, 3, 1, vi, 4, 10, 2, 12, 3, four, 1, 8, half-dozen, xviii, 4, 6, 10, 11, 2, 20, 12, xviii, iii, 28, four, v, ane, 10, 8, 12, 6, 36, xviii, 12, iv, 20, vi, 14, 10, 12, 11, ... (sequence A007733 in the OEIS).

Fractions with prime denominators [edit]

A fraction in everyman terms with a prime denominator other than ii or 5 (i.e. coprime to 10) always produces a repeating decimal. The length of the repetend (period of the repeating decimal segment) of ane / p is equal to the guild of 10 modulo p. If 10 is a archaic root modulo p, the repetend length is equal to p − i; if not, the repetend length is a factor of p − 1. This result can exist deduced from Fermat's little theorem, which states that ten p−1 ≡ 1 (mod p).

The base of operations-10 repetend of the reciprocal of whatever prime number number greater than 5 is divisible by ix.[4]

If the repetend length of 1 / p for prime p is equal to p − 1 then the repetend, expressed equally an integer, is chosen a cyclic number.

Cyclic numbers [edit]

Examples of fractions belonging to this group are:

  • i / 7 = 0.142857, half-dozen repeating digits
  • one / 17 = 0.0588235294117647, sixteen repeating digits
  • 1 / 19 = 0.052631578947368421, eighteen repeating digits
  • 1 / 23 = 0.0434782608695652173913, 22 repeating digits
  • 1 / 29 = 0.0344827586206896551724137931, 28 repeating digits
  • i / 47 = 0.0212765957446808510638297872340425531914893617, 46 repeating digits
  • 1 / 59 = 0.0169491525423728813559322033898305084745762711864406779661, 58 repeating digits
  • 1 / 61 = 0.016393442622950819672131147540983606557377049180327868852459, sixty repeating digits
  • ane / 97 = 0.010309278350515463917525773195876288659793814432989690721649484536082474226804123711340206185567, 96 repeating digits

The list can go on to include the fractions 1 / 109 , 1 / 113 , 1 / 131 , 1 / 149 , 1 / 167 , ane / 179 , ane / 181 , 1 / 193 , etc. (sequence A001913 in the OEIS).

Every proper multiple of a cyclic number (that is, a multiple having the same number of digits) is a rotation:

  • ane / vii = ane × 0.142857... = 0.142857...
  • 2 / 7 = two × 0.142857... = 0.285714...
  • 3 / seven = 3 × 0.142857... = 0.428571...
  • iv / 7 = 4 × 0.142857... = 0.571428...
  • v / 7 = five × 0.142857... = 0.714285...
  • 6 / 7 = 6 × 0.142857... = 0.857142...

The reason for the cyclic beliefs is apparent from an arithmetic exercise of long segmentation of ane / 7 : the sequential remainders are the cyclic sequence {i, three, two, 6, 4, 5}. See likewise the article 142,857 for more properties of this cyclic number.

A fraction which is cyclic thus has a recurring decimal of even length that divides into ii sequences in nines' complement form. For instance one / 7 starts '142' and is followed by '857' while 6 / seven (by rotation) starts '857' followed by its nines' complement '142'.

The rotation of the repetend of a circadian number always happens in such a way that each successive repetend is a bigger number than the previous 1. In the succession above, for case, we come across that 0.142857... < 0.285714... < 0.428571... < 0.571428... < 0.714285... < 0.857142.... This, for cyclic fractions with long repetends, allows u.s.a. to hands predict what the result of multiplying the fraction past any natural number n volition be, equally long every bit the repetend is known.

A proper prime is a prime p which ends in the digit 1 in base x and whose reciprocal in base x has a repetend with length p − i. In such primes, each digit 0, 1,..., 9 appears in the repeating sequence the same number of times as does each other digit (namely, p − 1 / 10 times). They are:[5] : 166

61, 131, 181, 461, 491, 541, 571, 701, 811, 821, 941, 971, 1021, 1051, 1091, 1171, 1181, 1291, 1301, 1349, 1381, 1531, 1571, 1621, 1741, 1811, 1829, 1861,... (sequence A073761 in the OEIS).

A prime is a proper prime if and only if it is a full reptend prime number and congruent to 1 mod 10.

If a prime number p is both full reptend prime and safe prime, and so i / p volition produce a stream of p − i pseudo-random digits. Those primes are

seven, 23, 47, 59, 167, 179, 263, 383, 503, 863, 887, 983, 1019, 1367, 1487, 1619, 1823,... (sequence A000353 in the OEIS).

Other reciprocals of primes [edit]

Some reciprocals of primes that do not generate circadian numbers are:

  • ane / 3 = 0.three, which has a menstruation (repetend length) of 1.
  • 1 / 11 = 0.09, which has a catamenia of 2.
  • i / 13 = 0.076923, which has a period of 6.
  • 1 / 31 = 0.032258064516129, which has a period of 15.
  • one / 37 = 0.027, which has a period of 3.
  • 1 / 41 = 0.02439, which has a menstruation of 5.
  • i / 43 = 0.023255813953488372093, which has a flow of 21.
  • i / 53 = 0.0188679245283, which has a period of xiii.
  • 1 / 67 = 0.014925373134328358208955223880597, which has a period of 33.

(sequence A006559 in the OEIS)

The reason is that 3 is a divisor of 9, xi is a divisor of 99, 41 is a divisor of 99999, etc. To detect the catamenia of 1 / p , we tin can check whether the prime p divides some number 999...999 in which the number of digits divides p − 1. Since the menses is never greater than p − one, nosotros can obtain this by calculating 10 p−1 − 1 / p . For case, for xi nosotros get

10 11 i 1 xi = 909090909 {\displaystyle {\frac {10^{xi-1}-1}{xi}}=909090909}

and so by inspection notice the repetend 09 and period of 2.

Those reciprocals of primes tin can be associated with several sequences of repeating decimals. For example, the multiples of 1 / 13 can exist divided into two sets, with different repetends. The outset set is:

  • 1 / 13 = 0.076923...
  • 10 / xiii = 0.769230...
  • 9 / thirteen = 0.692307...
  • 12 / 13 = 0.923076...
  • three / 13 = 0.230769...
  • four / xiii = 0.307692...,

where the repetend of each fraction is a cyclic re-organisation of 076923. The second set up is:

  • 2 / 13 = 0.153846...
  • 7 / 13 = 0.538461...
  • v / thirteen = 0.384615...
  • 11 / 13 = 0.846153...
  • 6 / thirteen = 0.461538...
  • 8 / 13 = 0.615384...,

where the repetend of each fraction is a cyclic re-arrangement of 153846.

In general, the set of proper multiples of reciprocals of a prime number p consists of n subsets, each with repetend lengthk, where nk =p − 1.

Totient rule [edit]

For an arbitrary integer n, the length L(northward) of the decimal repetend of 1 / n divides φ(north), where φ is the totient office. The length is equal to φ(north) if and only if 10 is a primitive root modulo n.[6]

In item, information technology follows that L(p) = p − i if and simply if p is a prime and x is a archaic root modulo p. Then, the decimal expansions of n / p for n = 1, 2, ..., p − 1, all have menstruum p − 1 and differ only by a cyclic permutation. Such numbers p are chosen full repetend primes.

Reciprocals of composite integers coprime to 10 [edit]

If p is a prime other than two or 5, the decimal representation of the fraction ane / p 2 repeats:

1 / 49 = 0.020408163265306122448979591836734693877551.

The period (repetend length) 50(49) must exist a factor of λ(49) = 42, where λ(n) is known equally the Carmichael function. This follows from Carmichael's theorem which states that if n is a positive integer then λ(north) is the smallest integer m such that

a m 1 ( mod n ) {\displaystyle a^{yard}\equiv ane{\pmod {n}}}

for every integer a that is coprime to north.

The period of 1 / p 2 is normally pT p , where T p is the menstruum of one / p . In that location are iii known primes for which this is non truthful, and for those the period of 1 / p ii is the aforementioned every bit the period of ane / p considering p 2 divides 10 p−i−ane. These three primes are 3, 487, and 56598313 (sequence A045616 in the OEIS).[7]

Similarly, the catamenia of 1 / p grand is unremarkably p k–1 T p

If p and q are primes other than 2 or 5, the decimal representation of the fraction i / pq repeats. An instance is 1 / 119 :

119 = 7 × 17
λ(vii × 17) = LCM(λ(vii), λ(17)) = LCM(six, 16) = 48,

where LCM denotes the least common multiple.

The menstruation T of 1 / pq is a cistron of λ(pq) and information technology happens to be 48 in this instance:

1 / 119 = 0.008403361344537815126050420168067226890756302521.

The period T of i / pq is LCM(T p ,T q ), where T p is the menses of 1 / p and T q is the menstruation of i / q .

If p, q, r, etc. are primes other than 2 or five, and grand, , m, etc. are positive integers, then

i p m q r thousand {\displaystyle {\frac {1}{p^{yard}q^{\ell }r^{m}\cdots }}}

is a repeating decimal with a period of

LCM ( T p k , T q , T r 1000 , ) {\displaystyle \operatorname {LCM} (T_{p^{k}},T_{q^{\ell }},T_{r^{thou}},\ldots )}

where Tpk , Tq , Trg ,... are respectively the period of the repeating decimals i / pk , 1 / q , one / rm ,... as defined to a higher place.

Reciprocals of integers non coprime to 10 [edit]

An integer that is non coprime to 10 but has a prime cistron other than 2 or v has a reciprocal that is eventually periodic, merely with a non-repeating sequence of digits that precede the repeating part. The reciprocal can be expressed as:

1 two a v b p k q , {\displaystyle {\frac {1}{2^{a}5^{b}p^{thousand}q^{\ell }\cdots }}\,,}

where a and b are not both nix.

This fraction tin also be expressed every bit:

5 a b 10 a p k q , {\displaystyle {\frac {5^{a-b}}{10^{a}p^{k}q^{\ell }\cdots }}\,,}

if a > b, or as

2 b a 10 b p k q , {\displaystyle {\frac {2^{b-a}}{10^{b}p^{m}q^{\ell }\cdots }}\,,}

if b > a, or equally

1 10 a p k q , {\displaystyle {\frac {ane}{ten^{a}p^{k}q^{\ell }\cdots }}\,,}

if a = b.

The decimal has:

  • An initial transient of max(a,b) digits after the decimal indicate. Some or all of the digits in the transient can be zeros.
  • A subsequent repetend which is the same as that for the fraction ane / p1000 q .

For example ane / 28 = 0.03571428:

  • a = 2, b = 0, and the other factors pk q ⋯ = 7
  • there are two initial non-repeating digits, 03; and
  • there are 6 repeating digits, 571428, the same amount as 1 / 7 has.

Converting repeating decimals to fractions [edit]

Given a repeating decimal, it is possible to calculate the fraction that produces it. For example:

x {\displaystyle 10} = 0.333333 {\displaystyle =0.333333\ldots }
10 x {\displaystyle 10x} = 3.333333 {\displaystyle =3.333333\ldots } (multiply each side of the above line by 10)
ix 10 {\displaystyle 9x} = iii {\displaystyle =iii} (subtract the 1st line from the second)
10 {\displaystyle x} = iii 9 = i 3 {\displaystyle ={\frac {iii}{nine}}={\frac {1}{3}}} (reduce to lowest terms)

Some other example:

x {\displaystyle x} = 0.836363636 {\displaystyle =\ \ \ \ 0.836363636\ldots }
10 10 {\displaystyle 10x} = 8.36363636 {\displaystyle =\ \ \ \ viii.36363636\ldots } (move decimal to start of repetition = movement by 1 place = multiply by 10)
1000 10 {\displaystyle 1000x} = 836.36363636 {\displaystyle =836.36363636\ldots } (collate 2d repetition here with 1st above = move by 2 places = multiply by 100)
990 x {\displaystyle 990x} = 828 {\displaystyle =828} (decrease to articulate decimals)
10 {\displaystyle x} = 828 990 = 18 46 18 55 = 46 55 {\displaystyle ={\frac {828}{990}}={\frac {18\cdot 46}{18\cdot 55}}={\frac {46}{55}}} (reduce to everyman terms)

A shortcut [edit]

The process beneath can be practical in particular if the repetend has n digits, all of which are 0 except the concluding one which is ane. For instance for due north = vii:

ten = 0.000000100000010000001 10 7 x = ane.000000100000010000001 ( 10 7 ane ) x = 9999999 x = one x = ane x seven 1 = 1 9999999 {\displaystyle {\begin{aligned}x&=0.000000100000010000001\ldots \\10^{7}ten&=ane.000000100000010000001\ldots \\\left(ten^{seven}-ane\right)10=9999999x&=i\\x&={\frac {1}{ten^{7}-i}}={\frac {one}{9999999}}\end{aligned}}}

And so this particular repeating decimal corresponds to the fraction one / 10 n  − 1 , where the denominator is the number written as due north digits nine. Knowing just that, a general repeating decimal can be expressed as a fraction without having to solve an equation. For example, one could reason:

7.48181818 = seven.3 + 0.18181818 = 73 10 + 18 99 = 73 x + 9 2 ix 11 = 73 x + 2 eleven = xi 73 + 10 2 10 11 = 823 110 {\displaystyle {\begin{aligned}7.48181818\ldots &=7.3+0.18181818\ldots \\[8pt]&={\frac {73}{10}}+{\frac {eighteen}{99}}={\frac {73}{x}}+{\frac {9\cdot 2}{nine\cdot xi}}={\frac {73}{10}}+{\frac {ii}{11}}\\[12pt]&={\frac {11\cdot 73+10\cdot 2}{10\cdot 11}}={\frac {823}{110}}\stop{aligned}}}

Information technology is possible to get a general formula expressing a repeating decimal with an n-digit period (repetend length), beginning right after the decimal point, every bit a fraction:

x = 0. a one a 2 a due north ¯ 10 north x = a 1 a 2 a north . a i a ii a n ¯ ( 10 n 1 ) 10 = 99 99 x = a 1 a 2 a n 10 = a 1 a 2 a northward x n 1 = a 1 a 2 a n 99 99 {\displaystyle {\begin{aligned}x&=0.{\overline {a_{1}a_{2}\cdots a_{n}}}\\ten^{n}x&=a_{1}a_{ii}\cdots a_{n}.{\overline {a_{i}a_{2}\cdots a_{north}}}\\\left(10^{n}-1\right)10=99\cdots 99x&=a_{i}a_{two}\cdots a_{north}\\x&={\frac {a_{one}a_{2}\cdots a_{n}}{10^{north}-1}}={\frac {a_{i}a_{ii}\cdots a_{n}}{99\cdots 99}}\terminate{aligned}}}

More explicitly, one gets the post-obit cases:

If the repeating decimal is between 0 and 1, and the repeating block is n digits long, outset occurring right later the decimal point, then the fraction (not necessarily reduced) volition be the integer number represented by the due north-digit block divided by the one represented by n digits ix. For example,

  • 0.444444... = 4 / ix since the repeating block is four (a 1-digit cake),
  • 0.565656... = 56 / 99 since the repeating block is 56 (a 2-digit block),
  • 0.012012... = 12 / 999 since the repeating cake is 012 (a three-digit block); this further reduces to 4 / 333 .
  • 0.999999... = 9 / 9 = 1, since the repeating block is 9 (also a i-digit cake)

If the repeating decimal is as above, except that there are m (actress) digits 0 betwixt the decimal bespeak and the repeating n-digit cake, then one can just add k digits 0 after the n digits 9 of the denominator (and, every bit earlier, the fraction may subsequently be simplified). For example,

  • 0.000444... = 4 / 9000 since the repeating block is iv and this block is preceded by three zeros,
  • 0.005656... = 56 / 9900 since the repeating block is 56 and it is preceded by 2 zeros,
  • 0.00012012... = 12 / 99900 = 1 / 8325 since the repeating cake is 012 and it is preceded by 2 zeros.

Any repeating decimal not of the course described above tin be written as a sum of a terminating decimal and a repeating decimal of one of the two above types (actually the first blazon suffices, just that could crave the terminating decimal to be negative). For example,

  • 1.23444... = 1.23 + 0.00444... = 123 / 100 + 4 / 900 = 1107 / 900 + four / 900 = 1111 / 900
    • or alternatively one.23444... = 0.79 + 0.44444... = 79 / 100 + 4 / nine = 711 / 900 + 400 / 900 = 1111 / 900
  • 0.3789789... = 0.3 + 0.0789789... = 3 / 10 + 789 / 9990 = 2997 / 9990 + 789 / 9990 = 3786 / 9990 = 631 / 1665
    • or alternatively 0.3789789... = −0.6 + 0.9789789... = − 6 / 10 + 978/999 = − 5994 / 9990 + 9780 / 9990 = 3786 / 9990 = 631 / 1665

An even faster method is to ignore the decimal indicate completely and become similar this

  • 1.23444... = 1234 − 123 / 900 = 1111 / 900 (denominator has one 9 and two 0s because one digit repeats and in that location are ii non-repeating digits after the decimal point)
  • 0.3789789... = 3789 − iii / 9990 = 3786 / 9990 (denominator has three 9s and one 0 because three digits repeat and there is 1 non-repeating digit later the decimal point)

It follows that whatever repeating decimal with period north, and k digits after the decimal point that do not belong to the repeating function, tin can exist written equally a (not necessarily reduced) fraction whose denominator is (ten due north  − 1)10 one thousand .

Conversely the period of the repeating decimal of a fraction c / d will be (at most) the smallest number n such that x northward  − i is divisible by d.

For instance, the fraction two / 7 has d = vii, and the smallest grand that makes ten k  − 1 divisible by 7 is thou = vi, because 999999 = seven × 142857. The period of the fraction 2 / 7 is therefore six.

Repeating decimals as infinite series [edit]

A repeating decimal can also be expressed as an space series. That is, a repeating decimal can be regarded as the sum of an space number of rational numbers. To take the simplest example,

0. 1 ¯ = 1 10 + 1 100 + one 1000 + = n = 1 i 10 north {\displaystyle 0.{\overline {1}}={\frac {1}{ten}}+{\frac {1}{100}}+{\frac {1}{1000}}+\cdots =\sum _{north=ane}^{\infty }{\frac {ane}{10^{n}}}}

The above serial is a geometric series with the start term as 1 / 10 and the common factor 1 / ten . Because the absolute value of the mutual factor is less than i, we tin say that the geometric serial converges and find the exact value in the form of a fraction by using the post-obit formula where a is the commencement term of the series and r is the common factor.

a 1 r = 1 10 1 one 10 = 1 10 ane = ane 9 {\displaystyle {\frac {a}{1-r}}={\frac {\frac {i}{10}}{ane-{\frac {ane}{x}}}}={\frac {1}{10-i}}={\frac {1}{9}}}

Similarly,

0. 142857 ¯ = 142857 x 6 + 142857 10 12 + 142857 x 18 + = n = one 142857 10 6 north a 1 r = 142857 x 6 one 1 10 6 = 142857 x 6 ane = 142857 999999 = 1 7 {\displaystyle {\begin{aligned}0.{\overline {142857}}&={\frac {142857}{x^{6}}}+{\frac {142857}{10^{12}}}+{\frac {142857}{10^{18}}}+\cdots =\sum _{n=one}^{\infty }{\frac {142857}{10^{6n}}}\\[6px]\implies &\quad {\frac {a}{1-r}}={\frac {\frac {142857}{10^{6}}}{ane-{\frac {1}{10^{6}}}}}={\frac {142857}{ten^{6}-i}}={\frac {142857}{999999}}={\frac {1}{7}}\cease{aligned}}}

Multiplication and cyclic permutation [edit]

The cyclic behavior of repeating decimals in multiplication besides leads to the construction of integers which are cyclically permuted when multiplied by sure numbers. For case, 102564 × four = 410256. 102564 is the repetend of four / 39 and 410256 the repetend of 16 / 39 .

Other properties of repetend lengths [edit]

Various properties of repetend lengths (periods) are given by Mitchell[8] and Dickson.[nine]

  • The period of 1 / m for integer chiliad is ever ≤g − 1.
  • If p is prime, the menstruation of 1 / p divides evenly into p − 1.
  • If thou is composite, the menstruation of 1 / k is strictly less than k − 1.
  • The menstruation of c / thou , for c coprime to k, equals the period of 1 / thousand .
  • If 1000 = two a 5 b n where north > 1 and n is non divisible by 2 or v, and so the length of the transient of one / k is max(a,b), and the menstruation equals r, where r is the smallest integer such that 10 r ≡ i (modernistic northward).
  • If p, p′, p″,... are distinct primes, then the period of 1 / p p′ p″ equals the lowest mutual multiple of the periods of ane / p , ane / p′ , i / p″ ,....
  • If chiliad and grand′ have no mutual prime number factors other than 2 or 5, and then the period of 1 / k k′ equals the to the lowest degree common multiple of the periods of 1 / k and 1 / yard′ .
  • For prime p, if
period ( one p ) = period ( 1 p 2 ) = = menstruum ( 1 p thou ) {\displaystyle {\text{menstruum}}\left({\frac {1}{p}}\correct)={\text{period}}\left({\frac {1}{p^{2}}}\right)=\cdots ={\text{menses}}\left({\frac {1}{p^{m}}}\right)}
for some one thousand, but
catamenia ( 1 p k ) period ( 1 p m + i ) , {\displaystyle {\text{period}}\left({\frac {1}{p^{m}}}\right)\neq {\text{period}}\left({\frac {ane}{p^{thousand+i}}}\right),}
and then for c ≥ 0 we take
period ( 1 p yard + c ) = p c period ( ane p ) . {\displaystyle {\text{menses}}\left({\frac {1}{p^{yard+c}}}\right)=p^{c}\cdot {\text{period}}\left({\frac {1}{p}}\right).}
  • If p is a proper prime ending in a 1, that is, if the repetend of 1 / p is a circadian number of length p − 1 and p = tenh + 1 for some h, then each digit 0, one, ..., nine appears in the repetend exactly h = p − 1 / 10 times.

For some other properties of repetends, see likewise.[10]

Extension to other bases [edit]

Various features of repeating decimals extend to the representation of numbers in all other integer bases, not only base 10:

  • Whatever real number can be represented as an integer role followed past a radix bespeak (the generalization of a decimal point to non-decimal systems) followed by a finite or infinite number of digits.
  • If the base of operations is an integer, a terminating sequence obviously represents a rational number.
  • A rational number has a terminating sequence if all the prime factors of the denominator of the fully reduced fractional form are also factors of the base of operations. These numbers brand up a dense fix in Q and R .
  • If the positional numeral system is a standard one, that is information technology has base
b Z { ane , 0 , one } {\displaystyle b\in \mathbb {Z} \smallsetminus \{-one,0,1\}}
combined with a sequent gear up of digits
D := { d 1 , d 1 + ane , , d r } {\displaystyle D:=\{d_{1},d_{1}+one,\dots ,d_{r}\}}
with r := |b|, dr  := d1 + r − i and 0 ∈ D , then a terminating sequence is obviously equivalent to the aforementioned sequence with non-terminating repeating part consisting of the digit 0. If the base is positive, then there exists an order homomorphism from the lexicographical order of the correct-sided infinite strings over the alphabet D into some closed interval of the reals, which maps the strings 0.A 1 A 2...A north db and 0.A 1 A 2...(An +ane) d ane with Ai D and An db to the aforementioned real number – and there are no other duplicate images. In the decimal system, for example, in that location is 0.9 = 1.0 = 1; in the balanced ternary system there is 0.one = i.T = ane / 2 .
  • A rational number has an indefinitely repeating sequence of finite length l, if the reduced fraction's denominator contains a prime cistron that is non a factor of the base. If q is the maximal cistron of the reduced denominator which is coprime to the base of operations, fifty is the smallest exponent such that q divides b l − 1. Information technology is the multiplicative society ord q (b) of the residue class b mod q which is a divisor of the Carmichael function λ(q) which in plow is smaller than q. The repeating sequence is preceded by a transient of finite length if the reduced fraction also shares a prime number gene with the base. A repeating sequence
( 0. A 1 A 2 A ¯ ) b {\displaystyle \left(0.{\overline {A_{1}A_{two}\ldots A_{\ell }}}\right)_{b}}
represents the fraction
( A i A two A ) b b l 1 . {\displaystyle {\frac {(A_{1}A_{2}\ldots A_{\ell })_{b}}{b^{fifty}-i}}.}
  • An irrational number has a representation of space length that is not, from whatsoever point, an indefinitely repeating sequence of finite length.

For instance, in duodecimal, 1 / 2 = 0.6, 1 / three = 0.4, 1 / 4 = 0.3 and i / six = 0.2 all terminate; ane / v = 0.2497 repeats with period length 4, in dissimilarity with the equivalent decimal expansion of 0.2; 1 / 7 = 0.186A35 has flow 6 in duodecimal, but equally it does in decimal.

If b is an integer base and k is an integer,

1 thousand = 1 b + ( b k ) 1 b 2 + ( b k ) 2 b 3 + ( b k ) 3 b 4 + ( b g ) 4 b 5 + + ( b yard ) Due north 1 b N + {\displaystyle {\frac {1}{grand}}={\frac {one}{b}}+{\frac {(b-k)^{1}}{b^{ii}}}+{\frac {(b-yard)^{ii}}{b^{3}}}+{\frac {(b-one thousand)^{iii}}{b^{4}}}+{\frac {(b-k)^{4}}{b^{five}}}+\cdots +{\frac {(b-yard)^{N-1}}{b^{N}}}+\cdots }

For example ane / 7 in duodecimal:

1 / 7 = ( 1 / 10 + v / x2 + 21 / 103 + A5 / 10iv + 441 / 105 + 1985 / 106 + ...)base 12

which is 0.186A35 (base of operations 12). 10 (base of operations 12) is 12 (base 10), 102 (base 12) is 144 (base x), 21 (base 12) is 25 (base of operations 10), A5 (base of operations 12) is 125 (base ten), ...

Algorithm for positive bases [edit]

For a rational 0 < p / q < 1 (and base of operations bNorthward >1 ) there is the following algorithm producing the repetend together with its length:

                        function            b_adic            (            b            ,            p            ,            q            )            // b ≥ ii; 0 < p < q            static            digits            =            "0123..."            ;            // up to the digit with value b–one            begin            s            =            ""            ;            // the string of digits            pos            =            0            ;            // all places are right to the radix point            while            not            divers            (            occurs            [            p            ])            exercise            occurs            [            p            ]            =            pos            ;            // the position of the identify with remainder p            bp            =            b            *            p            ;                          z              =              flooring              (              bp              /              q              )              ;              // index z of digit within: 0 ≤ z ≤ b-1                                      p              =              b              *              pz              *              q              ;              // 0 ≤ p < q                        if            p            =            0            so            Fifty            =            0            ;            return            (            south            )            ;            end            if            due south            =            s            .            substring            (            digits            ,            z            ,            i            )            ;            // append the grapheme of the digit            pos            +=            one            ;            end            while            L            =            pos            -            occurs            [            p            ]            ;            // the length of the repetend (being < q)            // mark the digits of the repetend by a vinculum:            for            i            from            occurs            [            p            ]            to            pos            -            1            practice            substring            (            s            ,            i            ,            1            )            =            overline            (            substring            (            due south            ,            i            ,            one            ))            ;            end            for            return            (            southward            )            ;            stop            function          

The start highlighted line calculates the digit z.

The subsequent line calculates the new balance p′ of the partition modulo the denominator q. Equally a consequence of the floor function floor we have

b p q 1 < z = b p q b p q , {\displaystyle {\frac {bp}{q}}-1\;\;<\;\;z=\left\lfloor {\frac {bp}{q}}\correct\rfloor \;\;\leq \;\;{\frac {bp}{q}},} {\displaystyle {\frac {bp}{q}}-1\;\;<\;\;z=\left\lfloor {\frac {bp}{q}}\right\rfloor \;\;\leq \;\;{\frac {bp}{q}},}

thus

b p q < z q p := b p z q < q {\displaystyle bp-q<zq\quad \implies \quad p':=bp-zq<q}

and

z q b p 0 b p z q =: p . {\displaystyle zq\leq bp\quad \implies \quad 0\leq bp-zq=:p'\,.}

Because all these remainders p are non-negative integers less than q, there can be merely a finite number of them with the effect that they must recur in the while loop. Such a recurrence is detected by the associative array occurs. The new digit z is formed in the yellow line, where p is the only non-constant. The length L of the repetend equals the number of the remainders (see also section Every rational number is either a terminating or repeating decimal).

Applications to cryptography [edit]

Repeating decimals (also called decimal sequences) have establish cryptographic and error-correction coding applications.[11] In these applications repeating decimals to base 2 are generally used which gives ascension to binary sequences. The maximum length binary sequence for 1 / p (when ii is a archaic root of p) is given by:[12]

a ( i ) = 2 i mod p modernistic ii {\displaystyle a(i)=2^{i}{\bmod {p}}{\bmod {2}}}

These sequences of menstruum p − 1 accept an autocorrelation function that has a negative acme of −1 for shift of p − i / ii . The randomness of these sequences has been examined by diehard tests.[13]

See also [edit]

  • Decimal representation
  • Full reptend prime number
  • Midy'south theorem
  • Parasitic number
  • Trailing zero
  • Unique prime
  • 0.999..., a repeating decimal equal to ane
  • Pigeonhole principle

References and remarks [edit]

  1. ^ Courant, R. and Robbins, H. What Is Mathematics?: An Uncomplicated Approach to Ideas and Methods, 2d ed. Oxford, England: Oxford University Press, 1996: p. 67.
  2. ^ Beswick, Kim (2004), "Why Does 0.999... = i?: A Perennial Question and Number Sense", Australian Mathematics Teacher, sixty (four): vii–ix
  3. ^ For a base b and a divisor n, in terms of group theory this length divides
    ord north ( b ) := min { Fifty N b 50 1  mod due north } {\displaystyle \operatorname {ord} _{n}(b):=\min\{Fifty\in \mathbb {N} \,\mid \,b^{50}\equiv 1{\text{ mod }}due north\}}
    (with modular arithmetics ≡ one mod n ) which divides the Carmichael function
    λ ( n ) := max { ord northward ( b ) gcd ( b , north ) = 1 } {\displaystyle \lambda (n):=\max\{\operatorname {ord} _{due north}(b)\,\mid \,\gcd(b,due north)=ane\}}
    which again divides Euler'southward totient function φ(due north).
  4. ^ Grey, Alexander J., "Digital roots and reciprocals of primes", Mathematical Gazette 84.09, March 2000, 86.
  5. ^ Dickson, L. E., History of the Theory of Numbers, Volume 1, Chelsea Publishing Co., 1952.
  6. ^ William E. Heal. Some Backdrop of Repetends. Annals of Mathematics, Vol. 3, No. 4 (Aug., 1887), pp. 97–103
  7. ^ Albert H. Beiler, Recreations in the Theory of Numbers, p 79
  8. ^ Mitchell, Douglas W., "A nonlinear random number generator with known, long cycle length", Cryptologia 17, January 1993, 55–62.
  9. ^ Dickson, Leonard E., History of the Theory of Numbers, Vol. I, Chelsea Publ. Co., 1952 (orig. 1918), 164–173.
  10. ^ Armstrong, N. J., and Armstrong, R. J., "Some backdrop of repetends", Mathematical Gazette 87, Nov 2003, 437–443.
  11. ^ Kak, Subhash, Chatterjee, A. "On decimal sequences". IEEE Transactions on Information Theory, vol. Information technology-27, pp. 647–652, September 1981.
  12. ^ Kak, Subhash, "Encryption and error-correction using d-sequences". IEEE Trans. On Computers, vol. C-34, pp. 803–809, 1985.
  13. ^ Bellamy, J. "Randomness of D sequences via diehard testing". 2013. arXiv:1312.3618

External links [edit]

  • Weisstein, Eric Westward. "Repeating Decimal". MathWorld.

davisrore1977.blogspot.com

Source: https://en.wikipedia.org/wiki/Repeating_decimal

0 Response to "How to Read Set a Repeating Decmel in C++"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel