您的位置:首页 > 大数据 > 人工智能

杭电1021Fibonacci Again

2016-04-04 14:05 363 查看

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

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector>

#define PI acos((double)-1)
#define E exp(double(1))
using namespace std;

int main (void)
{
int m;
while(scanf("%d",&m)==1)
{
m=(m-1)%8+1;
if(m==2||m==6)
cout<<"yes"<<endl;
else
cout<<"no\n";
}
return 0;
}
View Code

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: