|
发表于 2018-9-13 10:08:48
|
显示全部楼层
- def func207(n, c):
- #n表示需要输出的数字最小值屏蔽,屏蔽个位数,c表示需要多少个这样的数
- tmp = []
- for i in fab():
- if n <= i:
- tmplist=cushu(i)
- if tmplist:
- for a in tmplist:
- if i % a != 0:
- break
- else:
- tmp.append(i)
- if len(tmp) >= c:
- return tmp
- def cushu(l):
- tmplist = set()
- for j in str(l):
- if int(j) % 5 == 0:
- tmplist.add(5)
- if int(j) % 7 == 0:
- tmplist.add(7)
- if int(j) % 2 == 0:
- tmplist.add(2)
- if int(j) % 3 == 0:
- tmplist.add(3)
- if tmplist:
- return tmplist
- else:
- return
- def fab():
- n, a, b = 0, 0, 1
- while 1:
- yield b
- a, b = b, a + b
- n = n + 1
- import time
- start = time.time()
- print(func207(10, 10))
- print(time.time()-start)
复制代码
使用生成器的写法,yield的写法,不知道符不符合效率要求。 |
|