鱼C论坛

 找回密码
 立即注册
查看: 4004|回复: 12

题目55:10000以下有多少Lychrel数?

[复制链接]
发表于 2016-11-22 00:34:58 | 显示全部楼层
先算出非Lychrel数,再用9999-count
  1. def Rec(x):
  2.     tmp = list(str(x))
  3.     temp = tmp[:]
  4.     temp.reverse()
  5.     if tmp == temp:
  6.         return True
  7.     return False
  8. count = 0
  9. for i in range(1,10000):
  10.     pmt = i
  11.     for j in range(50):
  12.         tmp = ''
  13.         for n in range(1,len(str(pmt))+1):
  14.             tmp += str(pmt)[-n]
  15.         temp = pmt+int(tmp.lstrip('0'))
  16.         if Rec(temp):
  17.             count+=1
  18.             break
  19.         pmt = temp
  20.         
  21. print(9999-count)
复制代码

结果:249
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-9 06:36

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表