试题 C: 数列求值
本题总分: 10 分
【问题描述】
给定数列 1, 1, 1, 3, 5, 9, 17, …,从第 4 项开始,每项都是前 3 项的和。求第 20190324 项的最后 4 位数字。
Python代码处理结果如下:
a, b, c,= 1, 1, 1
d=0
count=3
while count < 20190324:
d=(a+b+c)%10000#处理大数据对每次结果都取余
count+=1
a, b, c= b,c,d
print(d)
答案4659
#答案40785
def m(num): #判断一个数中是否含有2或4
while(num>0):
k=num%10
if k==2 or k==4:
return False
num//=10
return True
count = 0
for a in range(1,2019):
for b in range(1,2019):
c=2019-a-b
if(m(a)and m(b)and m(c)) and a!=b and a!=c and b!=c and a!=b and c>0:
count=count+1
#print("{}+{}+{}={}".format(a,b,c,2019))
print(count/6)