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