Home » Java » ACM 1064: Xiaoming Zhongkai pig story [Java]

ACM 1064: Xiaoming Zhongkai pig story [Java]

Title Description


Saying that the price of pork is so expensive now, Xiao Ming has also started pig farming. It is strange that his pig will be born at noon every day for second days, and a pig will be born, and the sows are.But not even the piglets, Xiao Ming adopted a very strange way to manage his pig farm:

For each newborn piglet, he was killed immediately after birth of the first two piglets and sold to.
On the first day of the venture, Xiao Ming only bought a newborn piglet. How many pigs are there in Xiao Ming's pig farm on the night of N,

?
Input format


The first row of the test data is a positive integer T, which represents the number of test data. Then there is a T group test, each test data takes one row, respectively, a positive integer N, representing the day N of Xiao Ming's business. (0
output


For each data set, please in a row the N output night farms in the number of pigs.


sample input


2

2

3


sample output


2


3


by calculating the preceding days, the first day is 1, second days is 2, third is 3 days, fourth days is 5, fifth is 8, sixth days is 13. which is actually a Fibonacci sequence, behind a value equal to two in front of the values.

import java.util.Scanner;
Public class Xiaoming pig story {
Public, static, void, main (String, args[]) {
Scanner input = new Scanner (System.in);
While (input.hasNext ()) {
Int a = input.nextInt ();
For (int i = 0; I < A; i++) {
Int d = input.nextInt ();
If (D <20 & & D > 0) {
Int sum = 0;
Int e = 1;
Int c = 0;
For (int b = 0; B < D; B + +) {
Sum = C + e;
C = e;
E = sum;
}System.out.println (sum);
}
}
}
}
}


Latest