Fibonacci Again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50987    Accepted Submission(s): 24142

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
 

本题数据较大,故不适合用递推来解决,既然不能递推,我们很自然的就会想到找规律。

根据题目已知条件:
Print the word”yes” if 3 divide evenly into F(n);Print the word”no” if not.
这里mod取值为3,则可将公式条件演变为:
综上所述,可得到以下对应关系:F(0)= 1, F(1) = 2, F(n) = ( F(n-1) + F(n-2)  )( mod 3) (n>=2).
index  0  1  2  3  4  5  6  7  8  9  10  11  12  13
value  1  2  0  2  2  1  0  1  1  2   0   2   2  1
print  no no yes no  no no yes  no  no  no  yes  no  no  no
这样我们就得到了如下规律:从第2个开始每隔4个循环一次。

附AC代码:

 #include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(){
int n;
while(~scanf("%d",&n)){
if((n-)%)
printf("no\n");
else
printf("yes\n");
}
return ;
}

HDOJ-1021的更多相关文章

  1. 1021 Fibonacci Again (hdoj)

    Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) ...

  2. 杭电hdoj题目分类

    HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...

  3. HDOJ 题目分类

    HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:   ...

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  6. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  8. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  9. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  10. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

随机推荐

  1. 手写JQuery 的框架的实现

    JQuery的好处 快速上手(学习成本低) 开发效率高(选择器.批量操作 DOM.链型操作--) 一系列的封装(动画.ajax) 浏览器兼容(1.x版本 兼容IE6.7.8) JQuery 1.11. ...

  2. C#设计模式总结 C#设计模式(22)——访问者模式(Vistor Pattern) C#设计模式总结 .NET Core launch.json 简介 利用Bootstrap Paginator插件和knockout.js完成分页功能 图片在线裁剪和图片上传总结 循序渐进学.Net Core Web Api开发系列【2】:利用Swagger调试WebApi

    C#设计模式总结 一. 设计原则 使用设计模式的根本原因是适应变化,提高代码复用率,使软件更具有可维护性和可扩展性.并且,在进行设计的时候,也需要遵循以下几个原则:单一职责原则.开放封闭原则.里氏代替 ...

  3. Allegro基本操作——PCB布线

    转:http://blog.sina.com.cn/s/blog_1538bc9470102vyyq.html http://www.elecfans.com/article/80/110/2010/ ...

  4. vs2010音频文件压缩 调用lame_enc.dll将WAV格式转换成MP3

    /* //My_lame.h */ #pragma once#include "stdafx.h"#include <windows.h>#include <st ...

  5. Spring的常见问题及答案

    目录 Spring 概述 依赖注入 Spring beans Spring注解 Spring数据访问 Spring面向切面编程(AOP) Spring MVC Spring 概述 1. 什么是spri ...

  6. Storage,Memcache,KVDB都是存储服务,如何区分何时用何种服务

    Storage :是SAE为开发者提供的分布式文件存储服务,用来存放用户的持久化存储的文件.用户需要先在在线管理平台创建Domain(相当于一级子目录).    Storage为开发者提供分布式文件存 ...

  7. Recurrent neural networks are very powerful, because they combine two properties

    https://www.cs.toronto.edu/~hinton/csc2535/notes/lec10new.pdf Distributed hidden state that allows t ...

  8. java之冒泡排序

    //冒泡排序(Bubble Sorting)的基本思想是:通过对待排序序列从后向前(从下标较大的元素开始),依次比较相邻元素的排序码,若发现逆序则交换,使排序码较小的元素逐渐从后部移向前部(从下标较大 ...

  9. SQL的分页算法

    select top pageSize * from goods where goodsId not in (select top pageSize*(pageNow-1) goodsId from ...

  10. UI标签库专题四:JEECG智能开发平台 Upload(上传标签)

     1. Upload(上传标签) 1.1.  參数 属性名 类型 描写叙述 是否必须 默认值 id string 上传控件唯一标示 是 null name string 控件name 是 null ...