import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int a0 = scanner.nextInt(); int a1 = scanner.nextInt(); int p = scanner.nextInt(); int q = scanner.nextInt(); int k = scanner.nextInt(); int[] an = new int[k+1]; an[0]= a0; an[1]= a1; for (int i = 2; i <= k; i++) an[i]= (p*an[i-1]+q*an[i-2])%10000; System.out.println(an[k]); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner reader = new Scanner(System.in); while (reader.hasNext()) { int a0 = reader.nextInt(); int a1 = reader.nextInt(); int p = reader.nextInt(); int q = reader.nextInt(); int k = reader.nextInt(); long[] a = {a0, a1}; for (int i = 2; i <= k; ++i) { long tmp = p*a[1]%10000 + q*a[0]%10000; a[0] = a[1]; a[1] = tmp; } System.out.println(a[1]%10000); } } }
import java.util.Scanner; /** * Created by fhqplzj on 17-1-26 at 下午2:20. */ public class My6 { private static final int MOD = 10000; private static int getKth(int a0, int a1, int p, int q, int k) { a0 %= MOD; a1 %= MOD; if (k == 0) { return a0; } int a2 = a1; for (int i = 2; i <= k; i++) { a2 = ((p * a1 % MOD) + (q * a0 % MOD)) % MOD; a0 = a1; a1 = a2; } return a2; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextInt()) { int a0 = scanner.nextInt(); int a1 = scanner.nextInt(); int p = scanner.nextInt(); int q = scanner.nextInt(); int k = scanner.nextInt(); System.out.println(getKth(a0, a1, p, q, k)); } } }