Problem:


平方採中法

古典的な乱数生成方法の一つである平方採中法のプログラムを作成します。平方採中法は、フォンノイマンによって 1940 年代半ばに提案された方法です。

平方採中法は、生成する乱数の桁数を n としたとき、初期値 s の2乗を計算し、その数値を 2n 桁の数値とみて、（下の例のように 2 乗した桁数が足りないときは、0 を補います。）その中央にある n 個の数字を最初の乱数とします。次にこの乱数を 2 乗して、同じ様に、中央にある n 個の数字をとって、次の乱数とします。例えば、123 を初期値とすると

1232 = 00015129 → 0151
1512  = 00022801 → 0228
2282  = 00051984 → 0519
5192  = 00269361 → 2693
26932  = 07252249 → 2522

の様になります。この方法を用いて、初期値 s（10000未満の正の整数）を入力とし、n = 4 の場合の乱数を 10 個生成し出力するプログラムを作成してください。

Input

複数のデータセットが与えられます。１行目にデータセットの数 d (d ≤ 10) が与えられます。各データセットとして、１行に初期値 s（整数、1 ≤ s < 10000）が与えられます。

Output

各データセットに対して、

Case x: (x は 1 から始まるデータセット番号)
１個目の生成した乱数（整数）
２個目の生成した乱数（整数）
：
：
１０個目の生成した乱数（整数）

を出力してください。

Sample Input

2
123
567

Output for the Sample Input

Case 1:
151
228
519
2693
2522
3604
9888
7725
6756
6435
Case 2:
3214
3297
8702
7248
5335
4622
3628
1623
6341
2082



Sample input:
2
123
567


Sample output:
Case 1:
151
228
519
2693
2522
3604
9888
7725
6756
6435
Case 2:
3214
3297
8702
7248
5335
4622
3628
1623
6341
2082

Submission status: Wrong Answer

Solution code:
k = int(raw_input())

for j in range(k):
	x = int(raw_input())

	print("Case " + str(k + 1))
	for i in range(10):
		x = "00000000" + str(x**2)
		x = int(x[-6:-2])
		print(x)

Submission status: Wrong Answer

Solution code:
k = int(raw_input())

for j in range(k):
	x = int(raw_input())

	print("Case " + str(j + 1))
	for i in range(10):
		x = "00000000" + str(x**2)
		x = int(x[-6:-2])
		print(x)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

for j in range(n):
	x = int(raw_input())

	print("Case " + str(j + 1) + ":")
	for i in range(10):
		x = "00000000" + str(x**2)
		print(x)
		x = int(x[-6:-2])
		print(x)

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    s = int(raw_input())
    for i in range(10):
        n_s = str(s**2).zfill(8)[2:-2]
        for i, c in enumerate(n_s):
            if c != '0':
                s = int(n_s[i:])
                print s
                break

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    s = int(raw_input())
    print 'Case %s:' % str(i+1)
    for i in range(10):
        n_s = str(s**2).zfill(8)[2:-2]
        for i, c in enumerate(n_s):
            if c != '0':
                s = int(n_s[i:])
                print s
                break

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    s = int(raw_input())
    print 'Case %s:' % str(i+1)
    for i in range(10):
        n_s = str(s**2)
        if len(n_s) < 8:
            n_s = n_s.zfill(8)[2:-2]
        else:
            n_s = n_s[2:-2]
        for i, c in enumerate(n_s):
            if c != '0':
                s = int(n_s[i:])
                print s
                break

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    s = int(raw_input())
    print 'Case %s:' % str(i+1)
    for i in range(10):
        n_s = str(s**2)
        if len(n_s) < 8:
            n_s = n_s.zfill(8)[2:-2]
        else:
            n_s = n_s[-8:][2:-2]
        for i, c in enumerate(n_s):
            if c != '0':
                s = int(n_s[i:])
                print s
                break

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    s = int(raw_input())
    print 'Case %s:' % str(i+1)
    for i in range(10):
        n_s = str(s**2)
        if len(n_s) < 8:
            n_s = n_s.zfill(8)[2:-2]
        else:
            n_s = n_s[:8][2:-2]
        for i, c in enumerate(n_s):
            if c != '0':
                s = int(n_s[i:])
                print s
                break

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    s = int(raw_input())
    print 'Case ' + str(i+1) + ':'
    for i in range(10):
        n_s = str(s**2).zfill(8)[2:-2]
        for i, c in enumerate(n_s):
            if c != '0':
                s = int(n_s[i:])
                print s
                break

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    s = int(input())
    print("Case {}".format(i+1))
    for _ in range(10):
        s = int("{:08d}".format(s ** 2)[2:7])
        print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    s = int(input())
    print("Case {}:".format(i+1))
    for _ in range(10):
        s = int("{:08d}".format(s ** 2)[2:7])
        print(s)

Submission status: Wrong Answer

Solution code:
import os
import sys

def main():
    n = int(input())
    for i in range(1,n+1):
        x = int(input())
        print("Case {}:".format(i))
        for j in range(10):
            x = x**2
            out = '{0:08d}'.format(x)
            print(out[2:6])
            x = int(out[2:6])

main()

Submission status: Wrong Answer

Solution code:
import sys
R = lambda:map(int,raw_input().split())

digit = 4
n = int(raw_input())
for i in xrange(n):
    s = int(raw_input())
    ran = []
    for j in xrange(10):
        s2 = str(s*s)
        s2 = s2.zfill(8)
        #print s2
        s = int(s2[digit-2:digit+2])
        ran.append(s)

    print "Case %d" % (i+1)
    for j in xrange(len(ran)):
        print ran[j]

Submission status: Accepted

Solution code:
for i in range( int(raw_input())):
  print "Case %d:" %(i+1)
  a = int(float(raw_input()))
  for _ in [0]*10:
    a = int("{0:08d}".format(a*a)[2:6])
    print a

Submission status: Accepted

Solution code:
for i in range(int(raw_input())):
  print "Case %d:" %(i+1)
  a = int(raw_input())
  for _ in [0]*10:
    a = int("{0:08d}".format(a*a)[2:6])
    print a

Submission status: Accepted

Solution code:
n = int(raw_input())
for x in range(n):
    s = int(raw_input())
    print 'Case ' +str(x+1) + ':'
    
    tmp = str(s**2).zfill(8)
    for i in range(10):
        tmp2 = int(tmp[2:6])
        print tmp2
        tmp = str(tmp2**2).zfill(8)

Submission status: Accepted

Solution code:
n = int(raw_input())

for j in range(n):
	x = int(raw_input())

	print("Case " + str(j + 1) + ":")
	for i in range(10):
		x = "00000000" + str(x**2)
		x = int(x[-6:-2])
		print(x)

Submission status: Accepted

Solution code:
for i in range(input()):
    s = int(raw_input())
    print 'Case ' + str(i+1) + ':'
    for i in range(10):
        n_s = str(s**2).zfill(8)[2:-2]
        s = int(n_s)
        print s

Submission status: Accepted

Solution code:
for i in range(input()):
    s = int(raw_input())
    print 'Case %s:' % str(i+1)
    for i in range(10):
        n_s = str(s**2).zfill(8)[2:-2]
        s = int(n_s)
        print s

Submission status: Accepted

Solution code:
def doc_string():
	"""
	I can fly.
	"""

for i in xrange(int(raw_input())):
	x = str(int(raw_input()) ** 2)
	x = "0" * (8 - len(x)) + x
	
	print "Case " + str(i + 1) + ":"
	for _ in xrange(10):
		print int(x[2:6])
		x = str(int(x[2:6]) ** 2)
		x = "0" * (8 - len(x)) + x

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    cas = "Case " + str(i + 1) + ":"
    print(cas)
    num = int(input())
    for j in range(10):
        num = int((num ** 2) / 100)
        num = num % 10000
        print(num)

Submission status: Accepted

Solution code:
for i in range(int(input())):
    x = int(input())
    print("Case " + str(i+1) + ":")
    for _ in range(10):
        x = str(int(x)**2)
        if len(x) < 8 : x = (8-len(x))*"0" + x
        x = x[2:6]
        print(int(x))

Submission status: Accepted

Solution code:
for i in range(int(input())):
    a=str(int(input())**2).zfill(8)
    print('Case %d:'%(i+1))
    for _ in range(10):
        b=int(a[2:6])
        print(b)
        a=str(b**2).zfill(8)

Submission status: Accepted

Solution code:

def f(s):
  for j in range(10):
    s = s*s
    s = int(s/100)
    s = s%10000
    print(s)
    

n = int(input())
t = [int(input()) for i in range(n)]
for i in range(n):
  print("Case {0}:".format(i+1))
  f(t[i])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

N = int(input())
n = 4

for i in range(N):
    print("Case {}:".format(i+1))
    d = int(input())

    for j in range(10):
        square = d * d
        s = str(square).zfill(n*2)
        d = int(s[2:-2])
        print(d)

Submission status: Accepted

Solution code:
def cal(n):
    for i in range(0,10):
        n = (n*n / 100) % 10000
        print n

n = int(raw_input())

for i in range(0,n):
    print "Case %d:" % (i+1)
    n = int(raw_input())
    cal(n)

Submission status: Accepted

Solution code:
def main():
    d = int(input())
    a = []
    for _ in range(d):
        a.append(int(input()))

    ans = []
    for x in range(d):
        ansans = []
        hoge = a[x]
        for y in range(10):
            hoge = list("{0:08d}".format(hoge ** 2))
            s = ""
            for z in range(2, 6):
                s += hoge[z]
            hoge = int(s)
            ansans.append(hoge)
        ans.append(ansans)

    for x in range(1, d + 1):
        print("Case", x,end= "")
        print(":")
        for y in ans[x - 1]:
            print(y)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0137

"""
import sys
from sys import stdin
input = stdin.readline


def solve(i, n):
    result = []
    while len(result) < 10:
        i = i ** 2
        i //= 100  #  n???4??\?????????????
        i %= 10**n
        result.append(i)
    return result


def main(args):
    n = 4
    d = int(input())
    for i in range(1, d+1):
        init_value = int(input())
        result = solve(init_value, n)
        print('Case {}:'.format(i))
        print('\n'.join(map(str, result)))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# Aizu Problem 00137: Middle Square Method
#
import sys, math, os, copy

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def middle_square(k):
    for step in range(10):
        k = (k**2 // 100) % 10000
        print(k)
        
    
N = int(input())
for case in range(1, N + 1):
    print("Case %d:" % case)
    k = int(input())
    middle_square(k)

Submission status: Accepted

Solution code:
def main():
    d = int(input())
    a = []
    for _ in range(d):
        a.append(int(input()))

    for x in range(len(a)):
        print("Case ",end = "")
        print(x+1, end = "")
        print(":")
        for _ in range(10):
            a[x] = str("{0:08d}".format(a[x] ** 2))
            hoge = ""
            for y in range(2, 6):
                hoge += a[x][y]
            hoge = int(hoge)
            a[x] = hoge
            print(a[x])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    s = int(input())
    print("Case {}:".format(i+1))
    for _ in range(10):
        s = int("{:08d}".format(s ** 2)[2:6])
        print(s)

Submission status: Accepted

Solution code:
import os
import sys

def main():
    n = int(input())
    for i in range(1,n+1):
        x = int(input())
        print("Case {}:".format(i))
        for j in range(10):
            x = x**2
            out = '{0:08d}'.format(x)
            print(int(out[2:6]))
            x = int(out[2:6])

main()

Submission status: Accepted

Solution code:
def middle_square(s, digit):
    s2 = str(s ** 2).zfill(digit * 2)
    return int(s2[digit // 2:digit * 3 // 2])

n = int(input())

for i in range(n):
    print('Case {}:'.format(i + 1))

    s = int(input())
    for _ in range(10):
        s = middle_square(s, digit=4)
        print(s)

Submission status: Accepted

Solution code:
for lp in range(1, int(input()) + 1):

    num = int(input())

    print("Case " + str(lp) + ":")

    for _ in range(10):
        num **= 2
        num = str(num)
        num = "0" * (8 - len(num)) + num
        num = num[2:-2]
        num = int(num)
        print(num)

Submission status: Accepted

Solution code:
import math

N = int(input())

for l in range(N):

    k = int(input())

    print("Case " + str(l+1) + ":")
    for i in range(10):
        k = k*k
        k = k // 100
        k = k % 10000
        print(k)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
  print("Case ", i + 1, ":", sep="")
  x = input()
  for _ in range(10):
    x = str(int(x) ** 2).zfill(8)[2:6]
    print(int(x))

Submission status: Accepted

Solution code:
# AOJ 0137 Middle-Square Method
# Python3 2018.6.17 bal4u

for i in range(int(input())):
	print('Case ', i+1, ':', sep='')
	s = int(input())
	for j in range(10):
		s = (s * s // 100) % 10000
		print(s)

Submission status: Accepted

Solution code:
import sys
R = lambda:map(int,raw_input().split())

digit = 4
n = int(raw_input())
for i in xrange(n):
    s = int(raw_input())
    ran = []
    for j in xrange(10):
        s2 = str(s*s)
        s2 = s2.zfill(8)
        #print s2
        s = int(s2[digit-2:digit+2])
        ran.append(s)

    print "Case %d:" % (i+1)
    for j in xrange(len(ran)):
        print ran[j]

Submission status: Accepted

Solution code:
def generate_rand(n):
    num_digit = 4
    result = []
    for i in range(10):
        temp = str(n**2)
        temp = '0' * (8 - len(temp)) + temp
        result.append(int(temp[2:-2]))
        n = result[-1]
    return result

for i in range(int(raw_input())):
    n = int(raw_input())
    print "Case %d:" % (i + 1)
    for r in generate_rand(n):
        print r

Submission status: Accepted

Solution code:
def rand(s):
    for _ in xrange(10):
        s = int(str(s**2).zfill(8)[2:6])
        yield s

for i in range(input()):
    print "Case {}:".format(i+1)
    for r in rand(input()):
        print r

Submission status: Accepted

Solution code:
n = input()
for i in xrange(1,n+1):
    s = input()
    print "Case %d:"%i 
    for j in xrange(10):
        s = s*s
        s = int((("0"*(8-len(str(s))))+str(s))[2:6])
        print s

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
    s = int(raw_input())
    print "Case %d:"%(i+1)
    for j in range(10):
        if len(str(s**2)) < 3:
            s = 0
        else:
            s =int(str(s**2)[-6:-2])
        print s

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n):
    print("Case " + str(i + 1) + ":")
    num = int(input())
    for j in range(0,10):
        # 2乗
        num *= num
        sn = str(num)
        # 8桁にする
        if len(sn) < 8:
            d = 8 - len(sn)
            for k in range(d):
                sn = "0" + sn
        # 中央から値を取り出す
        num = int(sn[2:6])
        print(num)

Submission status: Accepted

Solution code:
digit = 100
def vrand(seed):
    del_down = int(seed * seed / digit)
    up_ = int(del_down / (digit * digit))
    up_ *= (digit * digit)
    return del_down - up_

num = int(input())
sds = []
for i in range(num):
    sd = int(input())
    sds.append(sd)

for i in range(num):
    print("Case "+str(i+1)+":")
    seed = sds[i]
    for j in range(10):
        seed = vrand(seed)
        print(seed)

Submission status: Accepted

Solution code:

c = int(input())
for i in range(c):
    s = int(input())
    print("Case {}:".format(i+1))
    for _ in range(10):
        tmp = "{:08d}".format(s**2)
        s = int(tmp[2:6])
        print(s)

Submission status: Accepted

Solution code:
def method(s):
    count=0
    ans=[]
    while count!=10:
        s=str(s**2).zfill(8)
        s=int(s[2]+s[3]+s[4]+s[5])
        ans.append(s)
        count +=1
    return ans
N=int(input())
for i in range(N):
    s=int(input())
    print("Case %d:"%(i+1))
    for j in range(10):
        print(method(s)[j])

Submission status: Accepted

Solution code:
x=int(input())
for i in range(x):
    n=int(input())
    print(f"Case {i+1}:")
    for j in range(10):
        n=int(str(n**2).zfill(8)[2:6])
        print(n)

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n):
    s = int(input())
    print("Case " + str(i+1) + ":")

    for _ in range(10):
        power = str(s**2).zfill(8)
        ans = power[2:6]
        print(int(ans))
        s = int(ans)

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n):
  print("Case ", i + 1, ":", sep="")
  x = input()
  for _ in range(10):
    x = str(int(x) ** 2).zfill(8)[2:6]
    print(int(x))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    print("Case",str(i+1)+":")
    tmp = input()
    for i in range(10):
        tmp = str(int(tmp)**2).zfill(8)[2:6]
        print(int(tmp))

Submission status: Runtime Error

Solution code:
import sys
def main():
    for line in sys.stdin:
        n = int(line)
        for x in range(1, n + 1):
            s = int(input())
            a = [] #answer
            for _ in range(10):
                s = "{0:08d}".format(s ** 2)
                s = list(s)
                hoge = ""
                for y in range(2, 6):
                    hoge += s[y]
                s = int(hoge)
                a.append(s)
            else:
                print("Case", x,end = "")
                print(":")
                for y in a:
                    print(y)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:

def main():
    n = int(iuput())
    for x in range(1, n + 1):
        s = int(input())
        a = [] #answer
        for _ in range(10):
            s = "{0:08d}".format(s ** 2)
            s = list(s)
            hoge = ""
            for y in range(2, 6):
                hoge += s[y]
            s = int(hoge)
            a.append(s)
        else:
            print("Case", x,end = "")
            print(":")
            for y in a:
                print(y)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(raw_input())
for i in range(n):
    s = int(raw_input())
    print "Case %d:"%(i+1)
    for j in range(10):
        s =int(str(s**2)[-6:-2])
        print s