编辑代码

function solution(n,m)
len=string.len(m)
num1={}
num2={}
num3={}
for i=0,len-1,1 do
    if m%10~=0 then
        num1[len-i-1]=m%10
    end
    if m%10==0 then
        num1[len-i-1]=0
    end
    m=m//10
end
    local step=1
for i=1,30,1 do

    for i=0,len-1,1 do
        num2[len-1-i]=num1[i]
    end
    for i=0,len,1 do
        num3[i]=0
    end
    for i=0,len-1,1 do
        num3[len-1-i]=num3[len-1-i]+num1[i]+num2[i]
    end
    for i=0,len-1,1 do
        if num3[i]>=n then
        num3[i]=num3[i]-n
        num3[i+1]=num3[i+1]+1
        end
    end
    if num3[len]~=0 then
        len=len+1
    end
    flag=0
    for i=0,len//2+1,1 do
        if num3[i]~=num3[len-1-i] then
        flag=1
        end
    end
    if flag==0 then
        print("STEP:")
        print(step)
        break
    end
    for i=0,len-1,1 do
        num1[i]=num3[len-1-i]
    end
    step=step+1
    if step==31 then
        print("impossible")
    end
end
end
n=io.read("*n")
m=io.read("*n")
solution(n,m)