# Period of repeating decimal

I came across of a 6-grader school problem to perform the following division 357.56/19. Pupils in the school understand that both numbers are numerically exact.

I would like to introduce Mathematica to children. How can I explain them how to solve this problem in MA? How can one find the period of this number?

N[35756/1900, 100]


for the first question. But I still do not know a simple answer for the second question.

• They expect sixth graders to cough up a decimal where the repeating segment has length 18? They must seriously dislike sixth graders. May 4, 2023 at 19:24
• @DanielLichtblau Yes, this is a real world case in Germany :) May 4, 2023 at 19:26
• And what do they do to seventh graders? Eat them? May 4, 2023 at 19:28
• No, that's what they do to ate graders May 4, 2023 at 19:49
• Is an answer based on MultiplicativeOrder out of bounds? Assuming the denominator is relatively prime to 10, the length is just MultiplicativeOrder[10, denominator] May 4, 2023 at 20:02

As written on MathWorld, you can use RealDigits.

r = 35756/1900;
RealDigits[r][[1, -1]]
(* {8,9,4,7,3,6,8,4,2,1,0,5,2,6,3,1,5,7} *)

Length[%]
(* 18 *)


Pedagocially, you should probably – as proposed by @MichaelE2 – present this in several steps. First defining the number, then observing the structure of RealDigits[r], then extracting parts of the results (also possible with First and Last), then counting the numbers ...

• And the period is? Notice, however, that [[1, -1]]´syntax might be hard to understand for children. May 4, 2023 at 19:14
• @yarchik: Dimensions[RealDigits[r][[1, -1]]][[1]] results in 18. May 4, 2023 at 19:55
• @yarchik I think you would have to explain the output syntax of RealDigits[r]. While clear (in a technical sense), the notation is new and unfamiliar and has lots of braces that mean nothing to a sixth-grade newbie. The [[-1, 1]] seems unnecessary, strictly speaking. They could copy and paste the answer from the output, if they needed to put the answer somewhere. May 4, 2023 at 22:31
• @MichaelE2 Yes, this is probably the way to go. May 5, 2023 at 5:49
• @yarchik, sorry, I somehow forgot about the period. May 5, 2023 at 7:03

To illustrate NestWhileList

f[x_, y_] :=
Module[{nst =
NestWhileList[QuotientRemainder[10 #, y][[2]] &,
QuotientRemainder[x, y][[2]], Unequal, All, Infinity]},
#2 - #1 & @@ (Flatten@Position[nst, nst[[-1]]])]


f[35756, 1900]` yields 18