New Fibonacci series and 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 <stdio. h> # define N 105int F [N]; // records the remainder of 3 in the recursive number pair. int I [N]; // record the input n values bool mark [N]; // mark whether the number is the remainder of 3. int main () {F [0] = 7; F [1] = 11; for (int I = 0; I <N; I ++) // tag initialization to falsemark [I] = false; for (I = 2; I <N; I ++) {// calculate the remainder of 3 on a recursive number 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; // important 1 Step to simplify the operation. Only 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 ;}
What is the Fibonacci series?
The famous Fibonacci series are defined as follows:
F (1) = 1, f (2) = 1, f (n) = f (n-1) + f (n-2), n> 2
In words, the Fibonacci sequence starts from 0 and 1, and the Fibonacci coefficient after is added by the previous two numbers. The first few Fibonacci coefficients are:
0, 1, 1, 2, 3, 5, 8, 13, 21
What is the formula for the Fibonacci series?
From the third item, each item is the sum of the previous two items, it is called the Fibonacci series, namely: 1, 1, 2, 3, 5, 8, 13 ,... ... 1 + 1... Later mathematicians discovered many characteristics related to the Fibonacci series.