I have written it directly on wiki4hp (and sorry for my english, i hope that others editors will fix it)

Here i copy only the pseudocode of the test:

k:= a number > 0

n:= a power 100^k

For i:=(n/10) to (n-1) do {

old := i

sequenceIsConvergent := false

limitCyclicSequences := 0 //because we can end in cyclic sequences and we don't want to use a lot of memory!

while ( (NOT sequenceIsConvergent) AND (limitCyclicSequences < n) ) {

new = extract_middle_number from old^2 (see below)

if new == old { //you can't use new == 0 here as a "fast" condition.

sequenceIsConvergent = true

}

else {

old := new

limitCyclicSequences = limitCyclicSequences+1;

}

}//end while

}//end for->Result: the time spent to finish the computation given the starting k value.

How does extract_middle_digits work?

Given n, that is a power of 10 of the tipe 10^d, its square is equal to 10^(d*2) and it has (d*2+1) digits.

We consider only the last (d*2). That is: of 10000*10000 = 100000000 we consider only 00000000 without the first 1.

Then we see all the numbers lower than 10^(d*2) with (d*2) digits, so if d=4,

we see 1542^2 as 02377764 instead of 2377764.

After that we pick the d=4 middle digits, from 02377764 we pick 02[3777]64.

So the middle number extracted is 3777.

Again, i hope that the admin of wiki4hp will be more tolerant, so users can edit directly the wiki page.

Oh, my hp50g is crunching the test with k=2 and several minutes have already passed.

*Edited: 10 Sept 2013, 7:26 p.m. *