 # PALIN: tle on the python script that is running on home system

This is the link to the question :

http://www.codechef.com/problems/PALIN

``````def pal(n):
d=n
num=0
d=n
while d!=0:
r=d%10
d/=10
num=num*10+r
if num==n:
return True
else:
return False

def n_pal(n):
n=n+1
while pal(n)==False:
n=n+1
return n

num=int(raw_input())
nums=[]
for i in range(0,num):
n=raw_input()
nums.append(n)

for i in range(0,num):
print(n_pal(int(nums[i])))
``````

I am compiling it through python 2.5 compiler but I am getting the Time exceed error.

Can anyone help me on this?

See the number could be 1000000 digit long and your division and modulus operations also depends on the number of digits. You need to get rid of these % and / operations. There is a simple approach to solve this problem. See the solutions there and figure out.

Thanks for your help but I cant get it where u say get rid of / and % operators then how would I do this question??

the words “radar”, or “abcdefedcba” are palindroms. to check that, you don’t need any modulo or division operations. try solving that problem without considering that input are integers (at least at the beginning). you should understand the proper method to do the required task quickly.