Project Euler #36: Double-base palindromes

  • + 0 comments

    100 points.

    def convert(n,b):
        if n==0:
            return 0
        res=''
        while n>0:
            n,r=divmod(n,b)
            res=str(r)+res
        return res    
    n,k=map(int,input().strip().split())
    s=0
    for i in range(1,n):
        c=convert(i,k)
        if str(i)==str(i)[::-1] and c==c[::-1]:
            s+=i
    print(s)