POJ 3982 序列

序列
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7705   Accepted: 3462

Description

数列A满足An = An-1 + An-2 + An-3, n >= 3 

编写程序,给定A0, A1 和 A2, 计算A99

Input

输入包含多行数据 

每行数据包含3个整数A0, A1, A2 (0 <= A0, A1, A2 <= 32767) 
数据以EOF结束

Output

对于输入的每一行输出A99的值

Sample Input

1 1 1

Sample Output

69087442470169316923566147


使用JAVA解决大数问题真的很方便

import java.util.Scanner;
	import java.math.*;
	public class Main{
		public static void main(String[] args){
			Scanner cin = new Scanner(System.in);
			BigInteger a, b, c, ans, temp1, temp2;
			while(cin.hasNextBigInteger()){
				a = cin.nextBigInteger();
				b = cin.nextBigInteger();
				c = cin.nextBigInteger();
				ans = c;
				int i = 3;
				while(i <= 99){
					temp1 = a.add(b);
					ans = temp1.add(c);
					a = b;
					b = c;
					c = ans;
					/*System.out.println(a);
					System.out.println(b);
					System.out.println(c);
					System.out.println(temp1);
					System.out.println(temp2);*/
					i++;
				}
				System.out.println(ans);
			}
		}
	}        


你可能感兴趣的:(POJ 3982 序列)