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. hdu3251 最小割

    题意: 给n个城市,m条有向边.每条边有权值,如今有些城市能够选择得到.可选的城市有一个价值.可是要满足从1到达不了这些城市,为了满足要求能够去掉一些边,须要花费边的权值,问终于得到的最大价值是多少, ...

  2. Class doesn&#39;t implement Cloneable之怪象

    1. 报错: -20 ::): threadid=: thread exiting with uncaught exception (group=0x4001d400) -20 ::): FATAL  ...

  3. iOS 获取图片某一点的颜色对象(UIColor*)。

    - (UIColor *)colorAtPixel:(CGPoint)point { // Cancel if point is outside image coordinates if (!CGRe ...

  4. Unity光滑与粗糙的材质——相似于生锈的金属表面

    纹理是在Photoshop中制作的,终于效果则是在Unity里得到的.这样的类型的材质.在3D游戏中非经常见.

  5. 用python编写的无线AP扫描器

    代码如下: #coding=utf-8 import os import sys import subprocess from scapy.all import * RSN = 48 #管理帧信息元素 ...

  6. erlang启动参数记录

    不管在erlang的shell下还是脚本里,启动参数都是非常有用的,抽空儿整理下erlang的常用启动参数: +A size   异步线程池的线程数,范围为0~1024,默认为10 +P Number ...

  7. toad for oracle中文显示乱码

    toad for oracle中文显示乱码 数据入库的时候中文显示正常,在toad for oracleclient和页面显示都是乱码!!! 原因:在数据入库时候出现的问题. 解决方式: 在系统变量中 ...

  8. netty+Protobuf (整合一)

    netty+Protobuf 整合实战 疯狂创客圈 死磕Netty 亿级流量架构系列之12 [博客园 总入口 ] 本文说明 本篇是 netty+Protobuf 整合实战的 第一篇,完成一个 基于Ne ...

  9. RequestDispatcher用法

    1.具体用法: RequestDispatcher dispatcher = req.getRequestDispatcher("updateByUserId_001.jsp"); ...

  10. 关于indexOf的使用

    今天项目中出现一个bug,在筛选数据的时候出现了冗余数据,查找发现在indexOf方法判断的时候找到了问题的所在. package demo; public class test { public s ...