There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
no
no
yes
no
no
no
题目意思很简单,给你一个类似于斐波那切数列的数列,询问你第n个数是否是3的倍数。
首先先看数据范围n<1000000,一看就知道模拟不能过。
所以就开始枚举找规律。
| 位置 |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
| 数值 |
7 |
11 |
18 |
29 |
47 |
76 |
123 |
| 对三取模后的值 |
1 |
2 |
0 |
2 |
2 |
1 |
0 |
然后发现第2个和第6个取模的值是一样的,于是就想是不是一个周期函数呢,继续枚举发现好像是,那么代码就非常简单了。
代码如下:
1 #include<cstdio>
2 #include<cmath>
3 #include<cstring>
4 #include<iostream>
5 using namespace std;
6 int main(){
7 int n;
8 while(scanf("%d",&n)!=EOF)
9 {
10 n=n+2;
11 if (n%4==0)
12 printf("yes\n");
13 else
14 printf("no\n");
15 }
16 return 0;
17 }