zoj 2060 Fibonacci Again(fibonacci数列规律、整除3的数学特性)

题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2060

题目描述:

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

 1 /*
 2 问题 对于定义的斐波那契数列,查询第n项是否能被3整除
 3 解题思路 首先直观的解法是将前100 0000项计算出来存在表里,再查询计算,但是直接计算的话100 0000项的斐波那契数
 4 是非常大的的,基本数据类型都是不够用的
 5 利用特性“一个数的各位数字之和能被3整除,那么这个数就能被3整除”,那么对每一位先对3取余,建立一个100 0000
 6 项的表,最后查询计算就可以了
 7 另外一个投机取巧的方法是可以发现每隔三个no就会出现一个yes,那么根据结果发现规律如果n%4 == 2则是no,否则是yes
 8 */ 
 9 #include <vector>
10 #include <cstdio>
11 using namespace std;
12 
13 int main()
14 {
15     vector<int> v;
16     int n1,n2,t,i;
17     n1=7%3;
18     n2=11%3;
19     v.push_back(n1);
20     v.push_back(n2);
21     for(i=2;i<=1000000;i++){
22         t=(n1+n2) %3;
23         v.push_back(t);
24         n1=n2;
25         n2=t;
26     }
27     int n;
28     while(scanf("%d",&n) != EOF)
29     {
30         if(v[n] % 3 == 0)
31             printf("yes\n");
32         else
33             printf("no\n");
34     }
35     /*while(scanf("%d",&n) != EOF)
36     {
37         if(n % 4 == 2)
38             printf("yes\n");
39         else
40             printf("no\n");
41     }*/ 
42     return 0;
43 }

 

转载于:https://www.cnblogs.com/wenzhixin/p/8543690.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值