Hangzhou Electric HDU 1021 Fibonacci Again

Source: Internet
Author: User

Fibonacci Again Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 41156 Accepted Submission (s): 19705


Problem Descriptionthere is another kind of Fibonacci numbers:f (0) = 7, f (1) = one, f (n) = f (n-1) + f (n-2) (n>=2).

Inputinput consists of a sequence of lines, each containing an integer n. (n < 1,000,000).

Outputprint the word "yes" if 3 divide evenly into F (n).

Print the word "no" if not.

Sample Input
012345

Sample Output
Nonoyesnonono

Authorleojay I say this topic want to be interesting, first go up to do, do not consider the array overflow n to hundreds of to die; the most critical point is that the question requires a judgment of whether or not, then look for the law, the result directly let him output 100 F "n" See if it can be divisible by 3 how the data is distributed, immediately encountered a surprise! Please see:
#include <iostream>using namespace Std;int main () {int n;int *ls=new int [10000000];ls[0]=7;ls[1]=11;for (int i=2;i <100;i++) {ls[i]=ls[i-1]+ls[i-2];/*if (ls[i]%3==0)      cout<< "yes" << "";  else  cout<< "no" << ""; */}while (cin>>n) {printf (n-1)%4==1? " Yes\n ":" no\n ");} printf (ls[n]%3? ") No ":" Yes "); return 0;}
Results The AC code can guess a few lines!! Oh, huh?
#include <iostream>using namespace Std;int main () {int N;while (cin>>n) {printf ((n-1)%4==1? ") Yes\n ":" no\n ");} return 0;}

Hangzhou Electric HDU 1021 Fibonacci Again

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.