# [seqfan] Re: Fw: NEW SEQ A164772

Fri Aug 28 16:36:53 CEST 2009

```(Re: Numbers n such that the average digit of n^2 is 8.)

I continued the search until 10^10 and found eight more terms. Here is
the complete list so far. Are there any patterns evident?

313,298327,9893887,197483417,282753937,314623583,315432874,
706399164,773303937,894303633,947047833,948675387,989938887,994987437,998398167
8882454614,8888194417,8943142063,9374913167,9416989417,9476286187,9949260676,9949823114

I am using a Python program for the search, and I have three
strategies to speed up the calculations.
1. Squares are generated by keeping a running total of consecutive odd numbers.
2. The digital sums of all numbers less than 10^6 are stored in a
lookup table. Repeated division by 10^6 is used to find the digital
sum of a larger number.
3. I am actually checking whether the digital sum of (10^d - 1 - k^2)
is equal to d, where d is the number of digits in k^2. The loop is
aborted when the sum of digits exceeds d.

I would be interested in other ideas to accelerate the search, other
than switching to C++. Here is my Python code.

k = 10104041174   # Starting value for search. Change to k=1 to start
at the beginning.

pow10 = 10
N = k**2
digits = 1
while pow10 <= N:
pow10 *= 10
digits += 1
n = pow10 - 1 - N
step = 2*k+1

block = 1000000
import scipy
digitsums = scipy.zeros(block,int)
for i in xrange(1,block):
digitsums[i] = digitsums[i/10] + (i % 10)

while 1:
if n < 0:
pow10 *= 10
digits += 1
n = pow10 - 1 - k*k
print "digits = %d" % (digits)
m = n
s = 0
while m>0:
s += digitsums[m % block]
if s > digits:
break
m /= block
else:
if s == digits:
print k
k += 1
n -= step
step += 2

```