冬雪雪冬 发表于 2018-9-10 10:37:31

Python:每日一题 206

本帖最后由 冬雪雪冬 于 2018-9-11 20:43 编辑

我们的玩法做了一下改变:

1. 楼主不再提供答案。
2. 请大家先独立思考,再参考其他鱼油的解答,这样才有助于自己编程水平的提高。开始阶段是看不到其他人的回帖的,等答题完成,开始评分时再取消限制。
3. 鼓励大家积极答题,奖励的期限为出题后24小时内。
4. 根据答案的质量给予1~3鱼币的奖励。

题目:
斐波那契数中有些数字是可以被其各位数字之和整除的,例如:
144可以被1+4+4整除。
要求求出前10个这样的斐波那契数(不包括一位数1, 2, 3, 5, 8)。

**** Hidden Message *****

塔利班 发表于 2018-9-10 10:43:40

本帖最后由 塔利班 于 2018-9-10 10:51 编辑

def fib():
    a,b=8,13
    while True:
      a,b=b,a+b
      if a%(sum(map(int,str(a))))==0:
            yield a
a=fib()
for i in range(10):
    print(next(a))

凌九霄 发表于 2018-9-10 11:03:22

本帖最后由 凌九霄 于 2018-9-10 14:33 编辑

def fibonacci(n):
    if n > 0:
      i, a, b = 0, 0, 1
      while i < n:
            a, b = b, a + b
            i += 1
      return a


i, j = 7, 0

while j < 10:
    f = fibonacci(i)
    t = eval('+'.join(str(f)))
    if not f % t:
      print(f)
      j += 1
    i += 1

chongchuigu 发表于 2018-9-10 11:17:31

def a206(n):
    a=1
    b=2
    while n:
      c=a+b
      s=str(c)
      s2=sum()
      if c%s2==0 and c>10:
            print(c)
            n-=1
      a=b
      b=c   
      
a206(10)

grf1973 发表于 2018-9-10 11:18:29

a,b,n=1,1,0
while n<10:
        b,a=a+b,b
        sumb=sum(int(x) for x in str(b))
        if b>10 and b%sumb==0:
                n+=1
                print(n,b)

JessiFly 发表于 2018-9-10 11:20:40

def fib():
    a,b = 0,1
    while True:
      a,b = b,a+b
      yield a

def my_filter(num):
    total = 0
    temp = num
    while num:
      total += num%10
      num //= 10
    if temp%total:
      return False
    else:
      return True

def fun206():
    count = 0
    for each_fib in fib():
      if each_fib > 10 and my_filter(each_fib):
            print(each_fib)
            count += 1
      if count == 10:
            break

if __name__ == '__main__':
    fun206()

huazai620 发表于 2018-9-10 11:32:01

学习

东土大谭 发表于 2018-9-10 11:50:51

1

胡尔汉 发表于 2018-9-10 11:52:27

def get_num(num):
    add = 0
    while num != 0:
      add += num%10
      num = num//10
    return add

x,y,i = 5,8,0
list1 = []
while i <10:
    x,y = y,x+y
    z = get_num(y)
    if y%z == 0:
      i +=1
      list1.append(y)
      
print(list1)

天圆突破 发表于 2018-9-10 12:01:03

from functools import reduce

class Feb:
    def __init__(self):
      self.a = self.b = 1
      
    def __iter__(self):
      return self

    def __next__(self):
      while True:
            self.a, self.b = self.b, self.a+self.b
            if self.a > 10 and self.a%reduce(lambda x,y:x+y, map(lambda x:int(x), list(str(self.a)))) == 0:
                return self.a

if __name__ == '__main__':
    for feb in Feb():
      print(feb)
      input()

Wangzy1025 发表于 2018-9-10 12:41:22

def feb():
    a, b = 8, 13
    while True:
      yield b
      a, b = b, a + b


def fun206(n=10):
    result = []
    for each in feb():
      if not each % (sum()):
            result.append(each)
      if len(result) == n:
            break
    return result


print(fun206())

阿池 发表于 2018-9-10 13:00:51

{:10_243:}

拉了盏灯 发表于 2018-9-10 13:08:31

def feb(n):
        a,b = 0,1
        while b<n:
                yield b
                a,b=b,a+b
def find_feb(lst):
        return
print(list(find_feb(feb(1 * 10**31))))

FC的注册很坑 发表于 2018-9-10 13:22:23

我敲的小代码算出14930352后就不太行了,算不出后面的数了,所以先回复下,看看隐藏内容是什么 {:10_266:}

FC的注册很坑 发表于 2018-9-10 13:32:50

本帖最后由 FC的注册很坑 于 2018-9-11 16:44 编辑

def fab(n):
    a=[]
    for i in range(0,n):
      if i==0:
            a.append(1)
      elif i==1:
            a.append(1)
      else:
            a.append(a+a)
    return a

def zc(n):
    st=str(n)
    l=len(st)
    sum=0
   
    for i in range(l):
      sum+=int(st)
    if n%sum==0:
      return True
    else:
      return False

count=7
total=1
while total<=10:
    a=fab(count)
    count+=1
    if zc(a):
      print(a,end=" ")
      total+=1
# 时间复杂度为O(lg n)
import numpy as np
def fab(n):
    k=np.array([,])
    a=np.array([,])
    for i in range(n-3):
      a=a@k
    return a

IChoose 发表于 2018-9-10 13:54:32

回复

黑白、 发表于 2018-9-10 14:10:19

本帖最后由 黑白、 于 2018-9-10 14:11 编辑

def fabSum(num):
    sum = 0
    temp = num
    while temp:
      sum = sum + temp%10
      temp //= 10
    return sum

def fun206(numMAX):
    each,a,b = 0,8,13
    while each < numMAX:
      sum = fabSum(b)
      if b%sum == 0:
            yield b
            a,b = b,a+b
            each += 1
      else:
            a,b = b,a+b

for each in fun206(10):
    print(each)

晓屁屁 发表于 2018-9-10 14:21:49

import sys
def fib():
    a = 0
    b = 1
    while b:
      yield b
      a, b = b, a + b
def change():
    list1 = []
    count = 0
    for i in fib():
      if len(list1) != 10:
            if len(str(i)) <= 1:
                pass
            else:
                for n in str(i):
                  count += int(n)
                if i % count == 0:
                  list1.append(i)
                  count = 0
                else:
                  count =0
      else:
            print(list1)
            sys.exit()
change()

IChoose 发表于 2018-9-10 14:27:40

i = 10
a1 = 3
a2 = 5
a3 = 8
while i:
    while 1:
      a1 = a2
      a2 = a3
      a3 = a1 + a2
      temp = a3
      sum = 0
      while temp:
            sum = sum + (temp%10)
            temp //= 10
      if not a3 % sum:
            print (a3)
            i -= 1
            break

raphael213 发表于 2018-9-10 15:11:50

本帖最后由 raphael213 于 2018-9-10 15:51 编辑

a, b, i = 0, 1, 0
list = []
while(i<10):
    a, b = b, a+b
    if a >10:
      sum,temp = 0,a
      while temp:
            sum = sum + (temp % 10)
            temp //= 10
      if a % sum == 0:
            list.append(a)
            i += 1
print(list)
页: [1] 2 3
查看完整版本: Python:每日一题 206