Hduoj1021【水题】
2015-07-27 16:21
204 查看
/*Fibonacci Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 44042 Accepted Submission(s): 21024 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 Author Leojay */ #include<stdio.h> int a[1000010]; int main() { int i, j, k; a[0] = 1; a[1] = 2; for(i = 2; i < 1000002; ++i) a[i] = (a[i-1] + a[i-2]) % 3; while(scanf("%d", &k) != EOF) if(a[k] == 0) printf("yes\n"); else printf("no\n"); return 0; }
题意:给出一个新的fib数列,给出一个n让你判断这个数是否是3的倍数。
思路:由于fib数列是累加的,所以我们可以用同于定理直接累加上去,即使n很大也不会超出范围。
相关文章推荐
- Android仿微信头部下拉菜单
- C++构造函数对类成员变量初始化,使用初始化列表和构造函数内部直接赋值 的区别
- hdoj1022火车进站(栈)
- 《配置Naigos nrpe的客户端(LINUX、Windows)》
- LeetCode Find Minimum in Rotated Sorted Array
- 面试经典(1)---翻转字的顺序在一个句子
- oracle 执行 delete user$ 误删所有用户信息后的数据恢复流程
- 【树分治】 HDOJ 5314 Happy King
- 在魅族官网,如何发帖?
- 页游中的十大经典游戏题材
- ZOJ - 2974 Just Pour the Water
- Nagios 监控Windows服务器(详细篇)
- nagios 执行check_disk时报错“NRPE: Command 'check_disk' not defined
- Android NDK进入发展
- 百度地图添加 标示——默认、自定义(小狐狸)标示
- 玩转Nodejs的集群
- 盒模型与布局相关属性
- 格而知之1:UIButton中imageView和titleLabel的位置调整
- asp.net c# 打开新页面或页面跳转
- ACM学习历程—SNNUOJ 1110 传输网络((并查集 && 离线) || (线段树 && 时间戳))(2015陕西省大学生程序设计竞赛D题)