A055642 Number of digits in the decimal expansion of n.
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
Offset: 0
Examples
Examples: 999: 1 + floor(log_10(999)) = 1 + floor(2.x) = 1 + 2 = 3 or ceiling(log_10(999+1)) = ceiling(log_10(1000)) = ceiling(3) = 3; 1000: 1 + floor(log_10(1000)) = 1 + floor(3) = 1 + 3 = 4 or ceiling(log_10(1000+1)) = ceiling(log_10(1001)) = ceiling(3.x) = 4; 1001: 1 + floor(log_10(1001)) = 1 + floor(3.x) = 1 + 3 = 4 or ceiling(log_10(1001+1)) = ceiling(log_10(1002)) = ceiling(3.x) = 4;
Links
- Charles R Greathouse IV, Table of n, a(n) for n = 0..10000
Crossrefs
Programs
-
Haskell
a055642 :: Integer -> Int a055642 = length . show -- Reinhard Zumkeller, Feb 19 2012, Apr 26 2011
-
Magma
[ #Intseq(n): n in [0..105] ]; // Bruno Berselli, Jun 30 2011 (Common Lisp) (defun A055642 (n) (if (zerop n) 1 (floor (log n 10)))) ; James Spahlinger, Oct 13 2012
-
Maple
A055642 := proc(n) max(1,ilog10(n)+1) ; end proc: # R. J. Mathar, Nov 30 2011
-
Mathematica
Join[{1}, Array[ Floor[ Log[10, 10# ]] &, 104]] (* Robert G. Wilson v, Jan 04 2006 *) Join[{1},Table[IntegerLength[n],{n,104}]] IntegerLength[Range[0,120]] (* Harvey P. Dale, Jul 02 2016 *)
-
PARI
a(n)=#Str(n) \\ M. F. Hasler, Nov 17 2008
-
PARI
A055642(n)=logint(n+!n,10)+1 \\ Increasingly faster than the above, for larger n. (About twice as fast for n ~ 10^7.) - M. F. Hasler, Dec 07 2018
-
Python
def a(n): return len(str(n)) print([a(n) for n in range(121)]) # Michael S. Branicky, May 10 2022
-
Python
def A055642(n): # Faster than len(str(n)) from ~ 50 digits on L = math.log10(n or 1) if L.is_integer() and 10**int(L)>n: return int(L or 1) return int(L)+1 # M. F. Hasler, Apr 08 2024
Formula
a(A046760(n)) < A050252(A046760(n)); a(A046759(n)) > A050252(A046759(n)). - Reinhard Zumkeller, Jun 21 2011
a(n) = 1 + floor(log_10(n)) = 1 + A004216(n) = ceiling(log_10(n+1)) = A004218(n+1), if n >= 1. - Daniel Forgues, Mar 27 2014
G.f.: g(x) = 1 + (1/(1-x))*Sum_{j>=0} x^(10^j). - Hieronymus Fischer, Jun 08 2012
a(n) = A262190(n) for n < 100; a(A262198(n)) != A262190(A262198(n)). - Reinhard Zumkeller, Sep 14 2015
Comments