import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner ss=new Scanner(System.in); short a=ss.nextShort(); short b=ss.nextShort(); int n=ss.nextInt(); while (a!=0 && b!=0 && n!=0) { System.out.println(f(n%49, a, b)); a=ss.nextShort(); b=ss.nextShort(); n=ss.nextInt(); } ss.close(); } private static byte f(int n,short a,short b) { if(n==1) return 1; if(n==2) return 1; return (byte)((f(n-1, a, b)*a+f(n-2, a, b)*b)%7); } }
原文:http://www.cnblogs.com/maydow/p/4498868.html