HDU 1021 Fibonacci Again( 同余水 )
**链接:****传送门 **
题意:现在给出 Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).问第 n 项能不能整除 3
思路:F(n) % 3 == 0 可以推导出 F(n) = ( F(n-1)%3 + F(n-2)%3 ) % 3 ,直接打个表判断 F(n) 是否为 0 即可
/*************************************************************************
> File Name: hdu1021.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月22日 星期一 10时51分29秒
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1000010;
int f[MAX_N];
void init(){
f[0] = 7; f[1] = 11;
for(int i = 2 ; i < MAX_N ; i ++){
f[i] = ( f[i-1]%3 + f[i-2]%3 )%3;
}
}
int main(){
init();
int n;
while(~scanf("%d",&n)){
if( f[n] == 0 ) printf("yes\n");
else printf("no\n");
}
return 0;
}
HDU 1021 Fibonacci Again( 同余水 )的更多相关文章
- hdu 1021 Fibonacci Again(找规律)
http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Others ...
- hdu 1021 Fibonacci Again(变形的斐波那契)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Ot ...
- ACM HDU 1021 Fibonacci Again
#include<iostream> using namespace std; int main() { int n; while(cin>>n) { if((n+1)%4== ...
- HDU 1021 - Fibonacci Again
找规律,分析让 F[N] 每一项对 3 取余的余数: 1,2,0, 2,2,1,0, 1,1,2,0, 2,2,1,0, 1,1,2,0, 2,2,1,0 ......... 显然循环了 #inclu ...
- HDU 1021 Fibonacci Again【打表找规律】
Fibonacci Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 同余定理简单应用 - poj2769 - hdu 1021 - hdu 2035
同余问题 基本定理: 若a,b,c,d是整数,m是正整数, a = b(mod m), c = d(mod m) a+c = b+c(mod m) ac = bc(mod m) ax+cy = bx+ ...
- 【HDU 1021】Fibonacci Again(找规律)
BUPT2017 wintertraining(16) #5 A HDU - 1021 题意 There are another kind of Fibonacci numbers: F(0) = 7 ...
- HDU 2096 小明A+B --- 水题
HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...
- HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)
HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的 ...
随机推荐
- ZOJ 3829 Known Notation(字符串处理 数学 牡丹江现场赛)
题目链接:problemId=5383">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5383 Do you ...
- 解题报告 之 HDU5303 Delicious Apples
解题报告 之 HDU5303 Delicious Apples Description There are n apple trees planted along a cyclic road, whi ...
- php json 初始化函数(格式化json字符串为php json_decode 标准的字符串)
$json="[{ 'i':100000, 'u':-1,n: '中国'},{i:100001,u:-1,n:'阿尔巴尼亚'},{i:100002,u:-1,n:'阿尔及利亚',}]&quo ...
- 如何让音频跟视频在ios跟android上自动播放
如何让音频跟视频在ios跟android上自动播放 <audio autoplay ><source src="audio/alarm1.mp3" type=&q ...
- JDBC基础01
今日知识 1. JDBC基本概念2. 快速入门3. 对JDBC中各个接口和类详解 JDBC: 1. 概念:Java DataBase Connectivity Java 数据库连接, Java语言操作 ...
- centos6.6--------正向DNS配置
一.正向区: 将域名解析为IP====================================================================================注 ...
- [Offer收割]编程练习赛38
漏写的数字 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #inclu ...
- BZOJ1060: [ZJOI2007]时态同步(树形dp 贪心)
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3285 Solved: 1286[Submit][Status][Discuss] Descript ...
- 自定义typecho后台路径
如何自定义后台路径 Typecho 安装好后,默认的后台路径是 domain.com/admin/,为了提高安全性,我们允许以 domain.com/xxxx/ 的方式访问,其中 xxxx 是你自定义 ...
- [OpenWrt]安装mjpg-streamer
安装mjpg-streamer 远程监控基本上是wifi小车的一个必备功能了.摄像头我用的是奥尼百脑通 D881,这个要100左右. 确认安装了以下软件: kmod-usb2 kmod-video-u ...