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

做这道题的思路来自hau oj 的另一道题

1005

Number Sequence

是一个周期的问题

/*思路如下,题目最终是要判断能否被3整除,那么在计算每一个 f(n)时,可以先对 3 求余,

那么,问题就转化为题号:1005   由于对 3 求余,那么结果就被控制在范围 0---2 ,当满足

f(n-1)=f(0)=7%3=1 并且 f(n)=f(1)=11%3=2时。break循环,而不必要算出全部 f(n)

此时以 i-2 作为一个周期 那么 f(n)=f(n%(i-2))  若f(n)==0  说明原f(n)能被3 整除*/

#include<cstdio>
int are[];
int main()
{
int i;
are[]=;
are[]=;
for(i=; i<; i++)
{
are[i]=(are[i-]+are[i-])%;
if(are[i]==&&are[i-]==)
break;
} int n;
while(scanf("%d",&n)!=EOF)
{
n=n%(i-);
if(are[n]==) printf("yes\n");
else printf("no\n"); }
return ;
}

Fibonacci Again的更多相关文章

  1. 算法与数据结构(九) 查找表的顺序查找、折半查找、插值查找以及Fibonacci查找

    今天这篇博客就聊聊几种常见的查找算法,当然本篇博客只是涉及了部分查找算法,接下来的几篇博客中都将会介绍关于查找的相关内容.本篇博客主要介绍查找表的顺序查找.折半查找.插值查找以及Fibonacci查找 ...

  2. #26 fibonacci seqs

    Difficulty: Easy Topic: Fibonacci seqs Write a function which returns the first X fibonacci numbers. ...

  3. 关于java的递归写法,经典的Fibonacci数的问题

    经典的Fibonacci数的问题 主要想展示一下迭代与递归,以及尾递归的三种写法,以及他们各自的时间性能. public class Fibonacci { /*迭代*/ public static ...

  4. 斐波拉契数列(Fibonacci) 的python实现方式

    第一种:利用for循环 利用for循环时,不涉及到函数,但是这种方法对我种小小白来说比较好理解,一涉及到函数就比较抽象了... >>> fibs = [0,1] >>&g ...

  5. fibonacci数列(五种)

    自己没动脑子,大部分内容转自:http://www.jb51.net/article/37286.htm 斐波拉契数列,看起来好像谁都会写,不过它写的方式却有好多种,不管用不用的上,先留下来再说. 1 ...

  6. POJ3070 Fibonacci[矩阵乘法]

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13677   Accepted: 9697 Descri ...

  7. Fibonacci 数列算法分析

    /************************************************* * Fibonacci 数列算法分析 ****************************** ...

  8. 算法系列:Fibonacci

    Copyright © 1900-2016, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ 欢迎转载,请保留此版权声明. -- ...

  9. UVa #11582 Colossal Fibonacci Numbers!

    巨大的斐波那契数 The i'th Fibonacci number f (i) is recursively defined in the following way: f (0) = 0 and  ...

  10. Buge's Fibonacci Number Problem

    Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, ...

随机推荐

  1. git pull --rebase

    git reset --hard orgin/master $ git push bit 1.8-subchannels To git@bitbucket.org:cms.git ! [rejecte ...

  2. ASP注入靶机

     ASP:   <%  Dim Db,MyDbPath dim conn '可修改设置一:========================定义数据库类别,1为SQL数据库,0为Access数据库 ...

  3. HDOJ 1026 dfs路径保存

    #include<cstdio> #include<cstring> #include<cmath> ][]; #define inf 0xffffff int n ...

  4. SphinxSE的安装

    SphinxSE 的使用 SphinxSE 的使用 :wiki SphinxSE是一个可以编译进MySQL 5.x版本的MySQL存储引擎,尽管被称作“存储引擎”,SphinxSE自身其实并不存储任何 ...

  5. Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  6. EtherCAT数据帧结构

    EtherCAT数据直接使用以太网数据帧(以太网帧解释http://blog.chinaunix.net/uid-23080322-id-118440.html)传输,使用的帧类型为0x88A4.Et ...

  7. 【转】 JSONObject使用方法

    随笔- 46  文章- 0  评论- 132 JSONObject简介 本节摘要:之前对JSON做了一次简单的介 绍,并把JSON和XML做了一个简单的比较:那么,我就在想,如果是一个json格式的字 ...

  8. 62. 链表重排[Reorder List]

    [本文链接] http://www.cnblogs.com/hellogiser/p/reorder-list.html [题目] Given a singly linked list L: L0→L ...

  9. cocos2dx3.0rc导出自定义类到lua的方法

    以前要导出c++类到lua,就得手动维护pkg文件,那简直就是噩梦,3.0以后就会感觉生活很轻松了. 转载请注明出处http://www.cnblogs.com/mrblue/p/3637910.ht ...

  10. iOS7 中的JavaScriptCore简单介绍

    以前写过一篇介绍如何使用第三方库在ios上进行js和oc交互调用的文章,链接如下 iOS 使用UIWebView把oc代码和javascript相关联.当时建立项目时,仍然是ios6时代,所以没有原生 ...