ZOJ 2060 A-Fibonacci Again
https://vjudge.net/contest/67836#problem/A
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
时间复杂度:$O(10^6)$
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e6 + 10;
int Fib[maxn]; int main() {
Fib[0] = 7, Fib[1] = 11;
for(int i = 2; i < maxn; i ++)
Fib[i] = (Fib[i - 1] + Fib[i - 2]) % 3; //同余定理
int n;
while(~scanf("%d", &n)) {
if(Fib[n] % 3)
printf("no\n");
else
printf("yes\n");
}
return 0;
}
ZOJ 2060 A-Fibonacci Again的更多相关文章
- ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!
两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...
- zoj 2060 Fibonacci Again(fibonacci数列规律、整除3的数学特性)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2060 题目描述: There are another kind ...
- [zoj 3774]Power of Fibonacci 数论(二次剩余 拓展欧几里得 等比数列求和)
Power of Fibonacci Time Limit: 5 Seconds Memory Limit: 65536 KB In mathematics, Fibonacci numbe ...
- zoj 1828 Fibonacci Numbers
A Fibonacci sequence is calculated by adding the previous two members of the sequence, with the firs ...
- ZOJ 3774 Fibonacci的K次方和
In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the f ...
- ZOJ 2672 Fibonacci Subsequence(动态规划+hash)
题意:在给定的数组里,寻找一个最长的序列,满足ai-2+ai-1=ai.并输出这个序列. 很容易想到一个DP方程 dp[i][j]=max(dp[k][i])+1. (a[k]+a[i]==a[j], ...
- zoj Fibonacci Numbers ( java , 简单 ,大数)
题目 //f(1) = 1, f(2) = 1, f(n > 2) = f(n - 1) + f(n - 2) import java.io.*; import java.util.*; imp ...
- ZOJ 3702 Fibonacci
解题思路: 找规律,不难的,打表 坑的地方在于题目限定条件 and the seed value for G(1) is a random integer t, (t>=1) 虽然都用粗体表示出 ...
- Fibonacci数列的幂和 zoj 3774
题目大意: 求斐波那契数列前n项的k次幂和 Mod 1000000009. n<=1e18, k<=1e5 这题的k比较大,所以不能用矩阵乘法来递推.学到了新姿势... http ...
随机推荐
- R语言学习笔记—决策树分类
一.简介 决策树分类算法(decision tree)通过树状结构对具有某特征属性的样本进行分类.其典型算法包括ID3算法.C4.5算法.C5.0算法.CART算法等.每一个决策树包括根节点(root ...
- 201552-53 《Java程序设计》第五周问题汇总
201552-53 <Java程序设计>第五周问题汇总 1.编译时,终端显示: 注:XXX.java使用了未经检查或不安全的操作,如何解决? 解答:并不是错误,可以忽视. 2.构造函数与类 ...
- 2016-2017-2 20155227实验二《Java面向对象程序设计》实验报告
2016-2017-2 20155227实验二<Java面向对象程序设计>实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉 ...
- 20155304 2016-2017-2《Java程序设计》课程总结
20155304 2016-2017-2<Java程序设计>课程总结 (按顺序)每周作业链接汇总 预备作业1:对自己专业看法及.学习Java的期望,以及心中的师生关系 预备作业2:有关技能 ...
- 20155328 《Java程序设计》实验三 敏捷开发与XP实践 实验报告
一.编码标准 编程标准包含:具有说明性的名字.清晰的表达式.直截了当的控制流.可读的代码和注释,以及在追求这些内容时一致地使用某些规则和惯用法的重要性. 下面是没有最基本的缩进的一个程序: publi ...
- 【vijos1049】送给圣诞夜的礼品
题面 描述 当小精灵们把贺卡都书写好了之后.礼品准备部的小精灵们已经把所有的礼品都制作好了.可是由于精神消耗的缘故,他们所做的礼品的质量越来越小,也就是说越来越不让圣诞老人很满意.可是这又是没有办法的 ...
- php 批量载入文件的几种方式
方式1:spl_autoload_register // Register the autoloader. /** * Contains the functionality for auto-load ...
- 利用存储过程生成大量的数据(oracle,mysql)
在进行查询操作的性能测试时,往往需要测试大数据量模式下的查询功能的性能,这是就需要我们去创造一些测试数据来填充数据库,来模拟真是环境,造数据的方式有很多种,可以使用loadrunner,jmeter等 ...
- 阿里云Ubuntu 14.04 + Nginx + .net core + MySql
前段时间帮朋友写了一个网站,现在做一个记录. .Net Core 安装: curl https://packages.microsoft.com/keys/microsoft.asc | gpg -- ...
- TPO 02 - Early Cinema
TPO 02 - Early Cinema NOTE: 主要意思(大概就是主谓宾)用粗体标出:重要的其它用斜体: []中的是大致意思,可能与原文有关也可能无关,但不会离题 目的为训练句子/段落总结能力 ...