Baekjoon 15841 Virus Outbreak JAVA

15841번: Virus Outbreak
For each input value, the output contains a line in the format: Hour X: Y cow(s) affected, where X is the hour, and Y is the total affected cows that need to be euthanized based on the hour given by X.
www.acmicpc.net
문제
The State Veterinary Services Department recently reported an outbreak of a newly found cow disease. All cows found to have affected by the disease have since euthanized because of the risk to the industry. Number of affected cows increased to 21, 34 and reached 55 after eight, nine and ten hours respectively.
You have been assigned by the authority to study the pattern of the outbreak and develop a program to predict the next number of affected cows so that the authorities could prepare and act accordingly.
입력
Input will consist of a series of positive integer numbers no greater than 490 each on a separate line represent the hours. The input process will be terminated by a line containing -1.
출력
For each input value, the output contains a line in the format: Hour X: Y cow(s) affected, where X is the hour, and Y is the total affected cows that need to be euthanized based on the hour given by X.
풀이
주어진 입력을 가지고, 규칙을 찾아서 피보나치 수열을 만드는 문제이다.
코드
import java.io.*;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n=0;
BigInteger [] arr = new BigInteger[500];
arr[0]=BigInteger.ZERO;
arr[1]=BigInteger.ONE;
for(int i=2;i<=490;i++)
arr[i]=arr[i-2].add(arr[i-1]);
while((n=Integer.parseInt(br.readLine()))!=-1) {
bw.write("Hour "+n+": "+arr[n]+" cow(s) affected\n");
}
bw.close();
}
}