HDU 1021 Fibonacci Again 数学题
2016-02-03 11:13
369 查看
[align=left]Problem Description[/align]
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
[align=left]Input[/align]
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
[align=left]Output[/align]
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
[align=left]Sample Input[/align]
0
1
2
3
4
5
[align=left]Sample Output[/align]
no
no
yes
no
no
no
题目意思很简单,给你一个类似于斐波那切数列的数列,询问你第n个数是否是3的倍数。
首先先看数据范围n<1000000,一看就知道模拟不能过。
所以就开始枚举找规律。
然后发现第2个和第6个取模的值是一样的,于是就想是不是一个周期函数呢,继续枚举发现好像是,那么代码就非常简单了。
代码如下:
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
[align=left]Input[/align]
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
[align=left]Output[/align]
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
[align=left]Sample Input[/align]
0
1
2
3
4
5
[align=left]Sample Output[/align]
no
no
yes
no
no
no
题目意思很简单,给你一个类似于斐波那切数列的数列,询问你第n个数是否是3的倍数。
首先先看数据范围n<1000000,一看就知道模拟不能过。
所以就开始枚举找规律。
位置 | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
数值 | 7 | 11 | 18 | 29 | 47 | 76 | 123 |
对三取模后的值 | 1 | 2 | 0 | 2 | 2 | 1 | 0 |
代码如下:
#include<cstdio> #include<cmath> #include<cstring> #include<iostream> using namespace std; int main(){ int n; while(scanf("%d",&n)!=EOF) { n=n+2; if (n%4==0) printf("yes\n"); else printf("no\n"); } return 0; }
相关文章推荐
- .net 4.5 async await 简单用法
- 个人电脑上搭建openstack的实验室http://geek.csdn.net/news/detail/53890
- 4320: ShangHai2006 Homework 并查集+离线处理 思路题
- error: command 'gcc' failed with exit status 1
- 4320: ShangHai2006 Homework|并查集
- 位图和矢量图区别,PS和AI的区别
- CDOJ 1270 Playfair
- 在Word 2010中,为粘贴无格式文本设置快捷键 Alt+V
- Spark PairRDD 转化二
- Light OJ 1038 Race to 1 Again (期望DP)
- poj2585 Window Pains(拓扑排序判定)
- 编译spark1.6.0出现 Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:exec (sparkr-pkg)
- 五子棋AI算法第二篇-极大极小值搜索算法
- USACO snail
- 杭电1021Fibonacci Again
- canvas和paint得简单应用
- BZOJ 3262 陌上花开、HDU 5618 Jam's problem again(三维偏序、cdq分治 + BIT)
- rails 分页插件 Kaminari 的 数组分页
- 【Elasticsearch】打分策略详解与explain手把手计算
- 解决'libproxychains.so.3' from LD_PRELOAD cannot be preloaded问题