鱼C论坛

 找回密码
 立即注册
查看: 7772|回复: 47

[技术交流] Python:每日一题 207

[复制链接]
发表于 2018-9-13 10:08:48 | 显示全部楼层
  1. def func207(n, c):
  2.     #n表示需要输出的数字最小值屏蔽,屏蔽个位数,c表示需要多少个这样的数
  3.     tmp = []
  4.     for i in fab():
  5.         if n <= i:
  6.             tmplist=cushu(i)
  7.             if tmplist:
  8.                 for a in tmplist:
  9.                     if i % a != 0:
  10.                         break
  11.                 else:
  12.                     tmp.append(i)
  13.         if len(tmp) >= c:
  14.             return tmp

  15. def cushu(l):
  16.     tmplist = set()
  17.     for j in str(l):
  18.         if int(j) % 5 == 0:
  19.             tmplist.add(5)
  20.         if int(j) % 7 == 0:
  21.             tmplist.add(7)
  22.         if int(j) % 2 == 0:
  23.             tmplist.add(2)
  24.         if int(j) % 3 == 0:
  25.             tmplist.add(3)
  26.     if tmplist:
  27.         return tmplist
  28.     else:
  29.         return
  30. def fab():
  31.     n, a, b = 0, 0, 1
  32.     while 1:
  33.         yield b
  34.         a, b = b, a + b
  35.         n = n + 1
  36. import time
  37. start = time.time()
  38. print(func207(10, 10))
  39. print(time.time()-start)
复制代码

使用生成器的写法,yield的写法,不知道符不符合效率要求。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-9-26 06:38

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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