HDU 1005 Number Sequence

来源:互联网 发布:双截龙2出招优化版 编辑:程序博客网 时间:2024/05/21 11:25


import java.math.BigInteger;
import java.util.Scanner;


public class Main {


static int a, b;
static long n;


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
a = scanner.nextInt();
b = scanner.nextInt();
n = scanner.nextLong();
if (n == 0)
return;
System.out.println(fun(n % 49));//除余n的平方
}
}


private static int fun(long i) {
if (i == 1 || i == 2)
return 1;
return (a * fun(i - 1) + b * fun(i - 2)) % 7;
}
}
0 0
原创粉丝点击