码迷,mamicode.com
首页 > 其他好文 > 详细

杭电1021Fibonacci Again

时间:2016-04-04 14:51:51      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

地址: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

标签:

原文地址:http://www.cnblogs.com/weeping/p/5351933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!