算法1
(递推)
a0, a1, p, q, k = map(int, input().split())
mod = 10000
a = [0 for i in range(k + 1) ]
a[0], a[1] = a0 % mod, a1 % mod
for i in range(2, k + 1):
a[i] = (p * a[i - 1] + q * a[i - 2]) % mod
print(a[k])
算法2
(递归)
a0, a1, p, q, k = map(int, input().split())
mod = 10000
def f(x):
if x == 1:
return a1
elif x == 0:
return a0
return (p * f(x - 1) + q * f(x - 2) ) % mod
print(f(k))