cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A051626 Period of decimal representation of 1/n, or 0 if 1/n terminates.

This page as a plain text file.
%I A051626 #89 Jul 02 2025 16:01:58
%S A051626 0,0,1,0,0,1,6,0,1,0,2,1,6,6,1,0,16,1,18,0,6,2,22,1,0,6,3,6,28,1,15,0,
%T A051626 2,16,6,1,3,18,6,0,5,6,21,2,1,22,46,1,42,0,16,6,13,3,2,6,18,28,58,1,
%U A051626 60,15,6,0,6,2,33,16,22,6,35,1,8,3,1,18,6,6,13,0,9,5,41,6,16,21,28,2,44,1
%N A051626 Period of decimal representation of 1/n, or 0 if 1/n terminates.
%C A051626 Essentially same as A007732.
%C A051626 For any prime number p: if a(p) > 0, a(p) divides p-1. - _David Spitzer_, Jan 09 2017
%H A051626 T. D. Noe, <a href="/A051626/b051626.txt">Table of n, a(n) for n = 1..10000</a>
%H A051626 Project Euler, <a href="https://projecteuler.net/problem=26">Reciprocal cycles: Problem 26</a>
%H A051626 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/RepeatingDecimal.html">Repeating Decimal</a>
%H A051626 <a href="/index/1#1overn">Index entries for sequences related to decimal expansion of 1/n</a>
%F A051626 a(n)=A132726(n,1); a(n)=a(A132740(n)); a(A132741(n))=a(A003592(n))=0. - _Reinhard Zumkeller_, Aug 27 2007
%e A051626 From _M. F. Hasler_, Dec 14 2015: (Start)
%e A051626 a(1) = a(2) = 0 because 1/1 = 1 and 1/2 = 0.5 have a finite decimal expansion.
%e A051626 a(3) = a(6) = a(9) = a(12) = 1 because 1/3 = 0.{3}*, 1/6 = 0.1{6}*, 1/9 = 0.{1}*, 1/12 = 0.08{3}* where the sequence of digits {...}* which repeats indefinitely is of length 1.
%e A051626 a(7) = 6 because 1/7 = 0.{142857}* with a period of 6.
%e A051626 a(17) = 16 because 1/17 = 0.{0588235294117647}* with a period of 16.
%e A051626 a(19) = 18 because 1/19 = 0.{052631578947368421}* with a period of 18. (End)
%p A051626 A051626 := proc(n) local lpow,mpow ;
%p A051626     if isA003592(n) then
%p A051626        RETURN(0) ;
%p A051626     else
%p A051626        lpow:=1 ;
%p A051626        while true do
%p A051626           for mpow from lpow-1 to 0 by -1 do
%p A051626               if (10^lpow-10^mpow) mod n =0 then
%p A051626                  RETURN(lpow-mpow) ;
%p A051626               fi ;
%p A051626           od ;
%p A051626           lpow := lpow+1 ;
%p A051626        od ;
%p A051626     fi ;
%p A051626 end: # _R. J. Mathar_, Oct 19 2006
%t A051626 r[x_]:=RealDigits[1/x]; w[x_]:=First[r[x]]; f[x_]:=First[w[x]]; l[x_]:=Last[w[x]]; z[x_]:=Last[r[x]];
%t A051626 d[x_] := Which[IntegerQ[l[x]], 0, IntegerQ[f[x]]==False, Length[f[x]], True, Length[l[x]]]; Table[d[i], {i,1,90}] (* _Hans Havermann_, Oct 19 2006 *)
%t A051626 fd[n_] := Block[{q},q = Last[First[RealDigits[1/n]]];If[IntegerQ[q], q = {}]; Length[q]];Table[fd[n], {n, 100}] (* _Ray Chandler_, Dec 06 2006 *)
%t A051626 Table[Length[RealDigits[1/n][[1,-1]]],{n,90}] (* _Harvey P. Dale_, Jul 03 2011 *)
%t A051626 a[n_] := If[ PowerMod[10, n, n] == 0, 0, MultiplicativeOrder[10, n/2^IntegerExponent[n, 2]/5^IntegerExponent[n, 5]]]; Array[a, 90] (* myself in A003592 and T. D. Noe in A007732 *) (* Robert G. Wilson v, Feb 20 2025 *)
%o A051626 (PARI) A051626(n)=if(1<n/=5^valuation(n,5)<<valuation(n,2),znorder(Mod(10,n)),0) \\ _M. F. Hasler_, Dec 14 2015
%o A051626 (Python)
%o A051626 def A051626(n):
%o A051626     if isA003592(n):
%o A051626         return 0
%o A051626     else:
%o A051626         lpow=1
%o A051626         while True:
%o A051626             for mpow in range(lpow-1,-1,-1):
%o A051626                 if (10**lpow-10**mpow) % n == 0:
%o A051626                     return lpow-mpow
%o A051626             lpow += 1 # _Kenneth Myers_, May 06 2016
%o A051626 (Python)
%o A051626 from sympy import multiplicity, n_order
%o A051626 def A051626(n): return 0 if (m:=(n>>(~n & n-1).bit_length())//5**multiplicity(5,n)) == 1 else n_order(10,m) # _Chai Wah Wu_, Aug 11 2022
%Y A051626 Essentially same as A007732. Cf. A002371, A048595, A006883, A036275, A114205, A114206, A001913.
%K A051626 nonn,base,easy
%O A051626 1,7
%A A051626 _J. Lowell_
%E A051626 More terms from _James Sellers_