题解 | #递推数列#

递推数列

https://www.nowcoder.com/practice/d0e751eac618463bb6ac447369e4aa25

def nextnum(a,b,p,q):
    return p*a+q*b

while True:
    try:
        a0,a1,p,q,k=map(int,input().strip().split())
        list1=[]
        list1.append(a0)
        list1.append(a1)
        for i in range(2,k+1):
            list1.append(nextnum(list1[i-1],list1[i-2],p,q))
        print(list1[k]%10000)
    except EOFError:
        break

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务