login
Numbers k such that k and k^2 have same digit sum.
24

%I #97 Dec 30 2023 23:52:30

%S 0,1,9,10,18,19,45,46,55,90,99,100,145,180,189,190,198,199,289,351,

%T 361,369,379,388,450,451,459,460,468,495,496,550,558,559,568,585,595,

%U 639,729,739,775,838,855,900,954,955,990,999,1000,1098,1099,1179,1188,1189

%N Numbers k such that k and k^2 have same digit sum.

%C It is interesting that the graph of this sequence appears almost identical as the maximum value of n increases by factors of 10. Compare the graph of the b-file (having numbers up to 10^6) with the plot of the terms up to 10^8. - _T. D. Noe_, Apr 28 2012

%C If iterated digit sum (A010888, A056992) is used instead of just digit sum (A007953, A004159), we get A090570 of which this sequence is a subset. - _Jeppe Stig Nielsen_, Feb 18 2015

%C Hare, Laishram, & Stoll show that this sequence (indeed, even its subsequence A254066) is infinite. In particular for each k in {846, 847, 855, 856, 864, 865, 873, ...} there are infinitely many terms in this sequence not divisible by 10 that have digit sum k. - _Charles R Greathouse IV_, Aug 25 2015

%C There are infinitely many n such that both n and n+1 are in the sequence. This includes A002283. - _Robert Israel_, Aug 26 2015

%H Zak Seidov, <a href="/A058369/b058369.txt">Table of n, a(n) for n = 1..8354</a> (to a(n) = 10^6)

%H Code Golf StackExchange, <a href="https://codegolf.stackexchange.com/questions/75384/equality-in-the-sum-of-digits">Equality in the sum of digits</a>, coding challenge started Mar 11 2016.

%H K. G. Hare, S. Laishram, and T. Stoll, <a href="http://arxiv.org/abs/1001.4170">The sum of digits of n and n^2</a>, International Journal of Number Theory 7:7 (2011), pp. 1737-1752.

%H T. D. Noe, <a href="/A058369/a058369.gif">Plot of terms up to 10^8</a>

%F A007953(a(n)) = A004159(a(n)). - _Reinhard Zumkeller_, Apr 25 2009

%e Digit sum of 9 = 9 9^2 = 81, 8+1 = 9 digit sum of 145 = 1+4+5 = 10 145^2 = 21025, 2+1+0+2+5 = 10 digit sum of 954 = 9+5+4 = 18 954^2 = 910116, 9+1+0+1+1+6 = 18. - Florian Roeseler (hazz_dollazz(AT)web.de), May 03 2010

%p sd := proc (n) options operator, arrow: add(convert(n, base, 10)[j], j = 1 .. nops(convert(n, base, 10))) end proc: a := proc (n) if sd(n) = sd(n^2) then n else end if end proc; seq(a(n), n = 0 .. 1400); # _Emeric Deutsch_, May 11 2010

%p select(t -> convert(convert(t,base,10),`+`)=convert(convert(t^2,base,10),`+`),

%p [seq(seq(9*i+j,j=0..1),i=0..1000)]); # _Robert Israel_, Aug 26 2015

%t Select[Range[0,1200],Total[IntegerDigits[#]]==Total[IntegerDigits[ #^2]]&] (* _Harvey P. Dale_, Jun 14 2011 *)

%o (Haskell)

%o import Data.List (elemIndices)

%o import Data.Function (on)

%o a058369 n = a058369_list !! (n-1)

%o a058369_list =

%o elemIndices 0 $ zipWith ((-) `on` a007953) [0..] a000290_list

%o -- _Reinhard Zumkeller_, Aug 17 2011

%o (PARI) is(n)=sumdigits(n)==sumdigits(n^2) \\ _Charles R Greathouse IV_, Aug 25 2015

%o (Magma) [n: n in [0..1200] |(&+Intseq(n)) eq (&+Intseq(n^2))]; // _Vincenzo Librandi_, Aug 26 2015

%o (Python)

%o def ds(n): return sum(map(int, str(n)))

%o def ok(n): return ds(n) == ds(n**2)

%o def aupto(nn): return [m for m in range(nn+1) if ok(m)]

%o print(aupto(1189)) # _Michael S. Branicky_, Jan 09 2021

%Y Cf. A002283, A007953, A058370, A058852, A077436, A254066.

%Y Cf. A147523 (number of numbers in each decade).

%Y Subsequence of A090570.

%K base,easy,nice,nonn

%O 1,3

%A _G. L. Honaker, Jr._, Dec 17 2000

%E Edited by _N. J. A. Sloane_, May 30 2010