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
-------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#define N 1000001
int ans[N]; int main()
{
int i; int n;
memset(ans, 0, sizeof(ans));
ans[0] = 7 % 3;
ans[1] = 11 % 3;
for (i = 2; i <= N; i++)
ans[i] = (ans[i - 1] + ans[i - 2]) % 3;
while (scanf("%d", &n) != EOF)
{
if (ans[n] == 0)
printf("yes\n");
else
printf("no\n");
}
return 0;
}

  

ACM1021:Fibonacci Again的更多相关文章

  1. 算法系列:Fibonacci

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

  2. lintcode:Fibonacci 斐波纳契数列

    题目: 斐波纳契数列 查找斐波纳契数列中第 N 个数. 所谓的斐波纳契数列是指: 前2个数是 0 和 1 . 第 i 个数是第 i-1 个数和第i-2 个数的和. 斐波纳契数列的前10个数字是: 0, ...

  3. POJ3070:Fibonacci——题解

    http://poj.org/problem?id=3070 题目大意:求Fibonacci数列第n项,对10000取模. 矩阵乘法板子题……实在不知道写什么了. #include<iostre ...

  4. 九度OJ 1092:Fibonacci (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1923 解决:1378 题目描述: The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} ...

  5. 蓝桥杯-入门训练 :Fibonacci数列

    问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1.当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少. 输入格式 输入包含一个整数n. ...

  6. 小总结:fibonacci数的产生

    我写的一个固定的函数来嘞: ]={,}; void f() { ;i<;i++) { fib[i]=fib[i-]+fib[i-]; } } 1,1,2,3,5,8,13,21,34,55,.. ...

  7. LintCode:Fibonacci

    C++ class Solution{ public: /** * @param n: an integer * @return an integer f(n) */ int fibonacci(in ...

  8. Codeforces Gym101205D:Fibonacci Words(KMP+递推)

    Gym 101205D 题意:f[0] = "0", f[1] = "1",接下来f[i] = f[i-1] + f[i-2],相当于字符串拼接.然后给出一个n ...

  9. Codechef:Fibonacci Number/FN——求通项+二次剩余+bsgs

    题意 定义 $F_n$ 为 $$F_n = \left\{\begin{matrix}0, n=0\\ 1, n=1 \\F_{n-1} + F_{n-2}, n > 1\end{matrix} ...

随机推荐

  1. golang 获取变量类型的字符串格式 列举变量类型

    fmt.Println(reflect.TypeOf(var)) switch xxx.(type){ case int:.... case float32:... case float64:... ...

  2. 细嚼慢咽C++primer(5)——顺序容器

    1 顺序容器的定义 容器是容纳特定类型对象的集合. 顺序容器:将单一类型元素聚集起来成为容器,然后根据位置来存储和访问这些元素,这就是顺序容器. 标准库的三种顺序容器类型:vector, list 和 ...

  3. MFC连接Mysql数据库执行查询和插入

    配置环境: include:mysql.h文件 lib:libmysql.lib文件 dll::libmysql.dll文件 连接代码: MYSQL m_sqlCon; MYSQL_RES *m_re ...

  4. Python实例---三级菜单的实现[high]

    # version: python3.2.5 # author: 'FTL1012' # time: 2017/12/7 09:16 menu = { '陕西': { '西安': { '未名区': [ ...

  5. Python实例---利用正则实现计算器[FTL版]

    import re # 格式化 def format_str(str): str = str.replace('--', '+') str = str.replace('-+', '-') str = ...

  6. MySQL 数据库--权限管理

    权限管理 1.创建账号 创建本地账号 create user 'luke'@'localhost' identified by '123'; #mysql -uluke -p123 创建远程账号 cr ...

  7. vector中删除的注意事项

    erase的函数原型有两种形式: iterator erase(iterator position); iterator erase(iterator first, iterator last); 例 ...

  8. Programming Assignment 2: Seam Carving

    编程作业二 作业链接:Seam Carving & Checklist 我的代码:SeamCarver.java 问题简介 接缝裁剪(Seam carving),是一个可以针对照片内容做正确缩 ...

  9. Apache Spark : RDD

    Resilient Distributed Datasets Resilient Distributed Datasets (RDD) is a fundamental data structure ...

  10. webpack环境搭建开发环境,JavaScript面向对象的详解,UML类图的使用

    PS:因为所有的设计模式都是基于面向对象来完成的,所以在讲解设计模式之前先来过一下面向对象都有哪些知识点 搭建开发环境 初始化npm环境 下载安装nodejs安装即可,nodejs自带npm管理包,然 ...