%I
%S 3,2,3,4,5,3,7,8,9,5,11,4,13,7,6,16,17,9,19,5,7,11,23,9,25,13,27,8,29,
%T 6,31,32,12,17,15,9,37,19,13,16,41,7,43,12,10,23,47,16,49,25,18,13,53,
%U 27,11,8,19,29,59,16,61,31,28,64,26,12,67,17,24,15,71
%N For n > 1, a(n) = least positive k, not a power of n, such that the digital sum of k in base n equals the digital sum of k^2 in base n.
%C For n > 2, a(n) <= n1 (and the sum of digits of a(n)^2 in base n equals a(n)).
%C The term a(10) = 9 belongs to A058369.
%C For any n > 1 and k >= 0:
%C  let d_n(k) be the digital sum of k in base n,
%C  we have d_n(1) = 1 and d_n(n1) = d_n((n1)^2),
%C  for any k such that 0 <= k <= n, we have d_n(k^2)  d_n(k) = d_n((nk)^2)  d_n(nk),
%C  for any even n > 2, d_n(n/2) != d_n((n/2)^2),
%C  hence, for any n > 2, either a(n) < n/2 or a(n) = n1,
%C  and the scatterplot of the sequence (for n > 2) has only points in the region y < x/2 and on the line y = x1.
%C Apparently (see colorized scatterplot in Links section):
%C  for any k > 0, a(2^k + 1) = 2^k,
%C  if n is odd and not of the form 2^k + 1, then a(n) <= (n1)/2.
%C See also A292788 for a similar sequence involving cubes instead of squares.
%H Rémy Sigrist, <a href="/A292787/a292787.png">Scatterplot of the sequence for n=2..10000</a>
%H Rémy Sigrist, <a href="/A292787/a292787_1.png">Colorized scatterplot of the sequence for n=2..10000</a>
%e For n = 8:
%e  1 is a power of 8,
%e  d_8(2) = 2 and d_8(2^2) = 4,
%e  d_8(3) = 3 and d_8(3^2) = 2,
%e  d_8(4) = 4 and d_8(4^2) = 2,
%e  d_8(5) = 5 and d_8(5^2) = 4,
%e  d_8(6) = 6 and d_8(6^2) = 8,
%e  d_8(7) = 7 and d_8(7^2) = 7,
%e  hence a(8) = 7.
%t With[{kk = 10^3}, Table[SelectFirst[Complement[Range[2, kk], n^Range@ Floor@ Log[n, kk]], Total@ IntegerDigits[#, n] == Total@ IntegerDigits[#^2, n] &] /. k_ /; MissingQ@ k > 1, {n, 2, 72}]] (* _Michael De Vlieger_, Sep 24 2017 *)
%o (PARI) a(n) = my (p=1); for (k=1, oo, if (k==p, p*=n, if (sumdigits(k,n) == sumdigits(k^2,n), return (k))))
%Y Cf. A058369, A292788.
%K nonn,base
%O 2,1
%A _Rémy Sigrist_, Sep 23 2017
