NZEC in Python

I am getting NZEC runtime error, please help me for this following code:

ch1 = input("")

ch = int(ch1[:1])

while (ch > 0):

kk = input("")
inp = kk[:3]
a, b = [int(i) for i in inp.split(' ')]
x = a**a
y = str(x)
x1 = y[:b]
x2 = y[-b:]
print x1, x2
ch = ch - 1

will you please say what the code is intended to do?

This is the question link:

are you inputting a string or a integer?

You are getting NZEC because you are calculating the complete value x = a ** a. Since the value of a is large (upto 10^9) the value a ** a will be very large and have billions of digits. Python stores this value as a string and as it cannot store such a large string in memory so it raises a memory exception which causes the NZEC error.

2 Likes

Such questions should preferably be posted as comments.It makes the post more readable

//