def ishuiwen(a):
b=a
a1=0
if a<10:
return True
else:
while(b>0):
a1=(a1*10)+b%10
b=b/10
if a1==a:
return True
else:
return False
n=int(raw_input('n:'))
s=10**n
s1=10**(n-1)
p=s-1
out=0
for i in range(p,s1-1,-1):
for j in range(i,s1-1,-1):
if i%10==0 or j%10==0:
continue
if ishuiwen(i*j):
ss=i*j
if ss>out:
out=ss
print out
但是时间复杂度过长,还需要优化