Palindrome from the product of two 3-digit numbers

后端 未结 6 1669
北海茫月
北海茫月 2020-12-20 08:12

I want to find the largest palindrome that can be obtained through the multiplication of two 3-digit numbers.

I started off with a and b both being 999, and to decre

6条回答
  •  渐次进展
    2020-12-20 08:53

    i = 1000000
    test = 0
    while test == 0:
        i += -1
        str_i = str(i)
        if str_i[0:3] == str_i[3:][::-1]:
            for j in range(100, 1000):
                if i % j == 0:
                    if i/j < 1000 and i/j > 100:
                        print('Largest Palindrome: %s = %s * %s' % (i, j, i//j))
                        test = 1
                        break
    

提交回复
热议问题