OFFSET
1,4
COMMENTS
If the decimal expansion of 1/n terminates, we will write it as ending with infinitely many 0's (rather than 9's). Then for any n > 1, the expansion of 1/n consists of a preamble whose length is given by A051628(n), followed by a periodic part with period length A007732(n). This sequence is defined as follows: If the only primes dividing n are 2 and 5 (see A003592), a(n) = A051628(n), otherwise a(n) = A007732(n) (and the preamble is ignored). - N. J. A. Sloane, Mar 22 2019
This sequence was discovered by a school class (aged 12-13) at Arden School, Solihull, UK.
EXAMPLE
1/1 is 1.0. There are no decimal digits, so a(1) = 0.
1/2 is 0.5. This is a terminating decimal. There is 1 digit, so a(2) = 1.
1/6 is 0.166666... This is a recurring decimal with a period of 1 (the initial '1' does not recur) so a(6) = 1.
1/7 is 0.142857142857... This is a recurring decimal, with a period of 6 ('142857') so a(7) = 6.
PROG
(Python)
def sequence(n):
..count = 0
..dividend = 1
..remainder = dividend % n
..remainders = [remainder]
..no_recurrence = True
..while remainder != 0:
....count += 1
....dividend = remainder * 10
....remainder = dividend % n
....if remainder in remainders:
......if no_recurrence:
........no_recurrence = False
........remainders = [remainder]
......else:
........return len(remainders)
....else:
......remainders.append(remainder)
..else:
....return count
(PARI) a(n) = my (t=valuation(n, 2), f=valuation(n, 5), r=n/(2^t*5^f)); if (r==1, max(t, f), znorder(Mod(10, r))) \\ Rémy Sigrist, May 08 2019
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Luke W. Richards, Mar 22 2019
EXTENSIONS
More terms from Rémy Sigrist, May 08 2019
STATUS
approved