杭电1021Fibonacci Again

Posted weeping

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了杭电1021Fibonacci Again相关的知识,希望对你有一定的参考价值。

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1021

题目:

Problem Description
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
 

 

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

 

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

Print the word "no" if not.
 

 

Sample Input
0
1
2
3
4
5
 

 

Sample Output
no
no
yes
no
no
no

 思路:(a+b)%c=a%c+b%c,所以可以把F(0)看做1,F(1)看做2,F(3)看做0,可以看出该数列一定会循环,(且最大循环节为9,因为3*3=9)。。。。。。以此类推.

  得到数列 (从0开始)1 2 0 2 2 1 0 1....(后面重复);

  所以。。。用n对8取模就好了。

   取模公式n=(n-1)%8+1;

ac代码:

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cmath>
 5 #include <cstring>
 6 #include <queue>
 7 #include <stack>
 8 #include <map>
 9 #include <vector>
10 
11 #define PI acos((double)-1)
12 #define E exp(double(1))
13 using namespace std;
14 
15 int main (void)
16 {
17     int m;
18     while(scanf("%d",&m)==1)
19     {
20         m=(m-1)%8+1;
21         if(m==2||m==6)
22             cout<<"yes"<<endl;
23         else
24             cout<<"no\\n";
25     }
26     return 0;
27 }
View Code

 

以上是关于杭电1021Fibonacci Again的主要内容,如果未能解决你的问题,请参考以下文章

1021 Fibonacci Again

HDU 1021 Fibonacci Again

HDU 1021 Fibonacci Again 数学题

hau1021 Fibonacci Again(递归)

hdu-1021 Fibonacci Again

hdu 1021 Fibonacci Again 找规律