New Fibonacci Series
Problem1:
Description:
Define a new Fibonacci sequence:
F (0) = 7;
F (1) = 11;
F (n) = F (n-1) + F (n-2); (n> = 2)
Input:
Multiple groups are input. First, enter N (N <= 100) to indicate the number of test cases to be input. Then, enter N numbers ni (ni <= 100 ), numbers are separated by spaces.
Output:
Determine whether F (n) can be divisible by 3. If yes, the output is 'yes'. Otherwise, the output is 'no '.
Sample input:
3 0 1 2
Sample output:
No
No
Yes
Tip: recursion is not supported; otherwise, the timeout occurs! During calculation, we do not need to calculate the real positive value of recursion. It will become larger and larger later, and Int may not be saved! The question is only required to calculate whether it is a multiple of 3. That is to say, no matter how big the value is, it is only three cases: 3n + 0, 3n + 1, 3n + 2, we only need to get the remainder of 3.
/** Description: New Fibonacci series * Author: Zhang yachao * blog: dunny's column http://blog.csdn.net/u012027907 * Date: */# include
# Define N 105int F [N]; // record the remainder of the Recurrence Number pair 3 int I [N]; // record the input n values bool mark [N]; // mark whether the corresponding number is the remainder of 3 int main () {F [0] = 7; F [1] = 11; for (int I = 0; I <N; I ++) // mark initialization as falsemark [I] = false; for (I = 2; I <N; I ++) {// calculate the remainder of a recursion number to 3 F [I] = F [I-1] + F [I-2]; if (F [I] % 3 = 0) // if it is a multiple of 3, mark [I] = true; F [I] % = 3; // an important step to simplify the operation, only store the remainder of 3} int n; while (scanf ("% d", & n )! = EOF) {for (int I = 0; I <n; I ++) {// enter scanf ("% d", & I [I]);} for (I = 0; I <n; I ++) {// output if (mark [I [I]) printf ("yes \ n "); elseprintf ("no \ n") ;}} return 0 ;}