HDU 1021 Fibonacci Again【打表找规律】
2024-09-05 20:13:08
Fibonacci Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 66450 Accepted Submission(s): 30760
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
1
2
3
4
5
Sample Output
no
no
yes
no
no
no
no
yes
no
no
no
【题意】:若F(n)%3==0输出yes
【分析】:根据打表找规律发现若n%4==2直接输出yes
【打表代码】:
#include<bits/stdc++.h>
using namespace std; int main()
{
int a[];
a[]=;
a[]=;
for(int i=;i<=;i++)
a[i]=a[i-]%+a[i-]%;
for(int i=;i<=;i++)
printf("%d\n",a[i]%);
}
打出部分表
【代码】:
#include<bits/stdc++.h>
using namespace std; int main()
{
int n;
while(cin>>n)
{
puts(n%==?"yes":"no");
}
}
注意yes大小写!
【总结】:一般看到【类斐波那契数列】【%某个数】就想到找规律、打表
最新文章
- ABP文档 :Overall - Module System
- NSCharacter​Set在字符串操作中得使用
- 转: Vue.js——60分钟组件快速入门(上篇)
- systemd的原理和适用方法
- Python3 基础
- gulp 前端自动化工具
- HTTP 教程 转自 http://www.w3cschool.cc/http/http-tutorial.html
- 深入探索C++对象模型-语义
- LESS使用介绍
- XISE菜刀V21.0 官网版 XISE菜刀VIP破解版 XISE官网
- 在没有DOM操作的日子里,我是怎么熬过来的(终结篇)
- CSS 背景图像 重复图像
- Django的模板系统
- 原型链上的call方法集合
- Spring boot actuator端点启用和暴露
- IBM推出新一代云计算技术来解决多云管理
- Java多线程-----创建线程的几种方式
- 基于SecureCRT的测试环境的克隆的linux/vi相关命令
- swift - 启动APP 黑屏
- Linux下通过管道杀死所有与tomcat相关的进程