New Fibonacci Series

Source: Internet
Author: User

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 ;}
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.