钱闻韬
发表于 2018-9-22 11:18:32
def fun207(n):
def fib():
a, b = 0, 1
while 1:
a, b = b, a + b
yield a
g = fib()
flt = filter(lambda x: len(str(x)) > 1 and not sum(map(lambda y, x=x: x % y, {int(i) for i in str(x)} - {0, 1})), g)
return
print(fun207(10))
乔一丨JOY
发表于 2018-9-23 07:46:04
小白前来学习
nononoyes
发表于 2018-10-9 14:52:08
666
wwhywhy
发表于 2018-10-10 10:48:05
非常好
一团守卫饭
发表于 2018-10-10 16:16:53
def fib(n):
a=1
b=1
if n == 1:
return 1
elif n==2:
return 1
else:
for i in range(2,n):
c=a
a=b
b=c+b
return b
def judge(x):
set1=set()
l=len(str(x))
for i in range(0,l):
set1.add(x//(10**(l-1)))
set1.add(x%(10**i)//(10**(i-1)))
set1.add(x%10)
set1.discard(0)
list1=list(set1)
for each in list1:
if x%each == 0:
pass
else:
return 0
return 1
i=7
count=0
while 1:
if judge(fib(i)):
count+=1
print(fib(i))
i+=1
if count==10:
break
sunrise085
发表于 2019-1-21 17:10:27
这个问题,我感觉从里面剔除2、3、4所占用的时间要多于判断2、3、4整除的时间(我还没有尝试,有以后试一下)。想加速,就把求斐波那契的过程省去,会快很多。
下面是我的程序:
def mylist(num):
result=[]
while num:
n=num%10
if not n in result and n!=0 and n!=1:
result.append(n)
num=num//10
if 9 in result:
if 3 in result:result.remove(3)
if 8 in result:
if 4 in result:result.remove(4)
if 2 in result:result.remove(2)
if 6 in result:
if 3 in result:result.remove(3)
if 2 in result:result.remove(2)
if 4 in result:
if 2 in result:result.remove(2)
return result
i,x1,x2=1,8,13
while i<=10:
list1=mylist(x2)
for n in list1:
if x2%n!=0:
break
else:
print('第%2d个数是%d' %(i,x2))
i+=1
x1,x2=x2,x1+x2
结果:
第 1个数是55
第 2个数是144
第 3个数是46368
第 4个数是5358359254990966640871840
第 5个数是64202014863723094126901777428873111802307548623680
第 6个数是769246427201094785080787978422393713094534885688979999504447628313150135520
第 7个数是9216845717656874712980450562726202415567360565980794777111390850331644813674856981646960226192287360
第 8个数是110433070572952242346432246767718285942590237357555606380008891875277701705731473925618404421867819924194229142447517901959200
第 9个数是1323171012053243520828784042795469593341319770463238313551473338336502410952765153371119398122747569819754164672344667591018783803781288766524146031040
第10个数是15853779289614481577191691577533518174485949824765525957623037737532160833631593681512535189759649213804709691705593604227037581022758330489263385511067756715301085561591382880
小陨aoq
发表于 2020-8-15 21:48:01
看看答案