The middle-square method is a method used to generate a sequence of pseudorandom numbers. To generate a sequence of
-digit numbers, an
-digit number
is chosen as the first number of the sequence.
is squared, producing a
digit number (padded with leading zeroes if it has less than
digits). The middle
digits of this square are used to form
, the next number in the sequence. This process is then repeated to generate more numbers.
Given , find the next
numbers in the sequence.
Input Specification
The first line of input will contain a positive even integer (
), the number of digits in each number of the sequence.
The second line of input will contain a positive integer , the first number of the sequence. This number might be padded with leading zeroes if it has less than
digits.
Output Specification
Output the next
-digit numbers in the sequence,
, each on a separate line, padded with leading zeroes if necessary.
Sample Input 1
6
123456
Sample Output 1
241383
265752
624125
532015
Sample Input 2
4
0123
Sample Output 2
0151
0228
0519
2693
Comments