杭电1021Fibonacci Again
2016-04-04 14:05
363 查看
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1021
题目:
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
思路:(a+b)%c=a%c+b%c,所以可以把F(0)看做1,F(1)看做2,F(3)看做0,可以看出该数列一定会循环,(且最大循环节为9,因为3*3=9)。。。。。。以此类推.
得到数列 (从0开始)1 2 0 2 2 1 0 1....(后面重复);
所以。。。用n对8取模就好了。
取模公式n=(n-1)%8+1;
ac代码:
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <stack> #include <map> #include <vector> #define PI acos((double)-1) #define E exp(double(1)) using namespace std; int main (void) { int m; while(scanf("%d",&m)==1) { m=(m-1)%8+1; if(m==2||m==6) cout<<"yes"<<endl; else cout<<"no\n"; } return 0; }View Code
相关文章推荐
- 解决sublimeText3无法安装插件有关问题 - There are no packages available for installation
- LeetCode Palindrome Pairs
- 服务器TIME_WAIT和CLOSE_WAIT详解和解决办法
- Tensorflow 官方版教程中文版
- 解决time_wait过多的问题
- 2016微软开发者大会 - 简洁收集
- 70. Climbing Stairs
- RAID各级别特性
- 学习笔记之RAID各级别特性
- wait()、notify()、notifyAll()
- 10013---Trail ~ Catalogs
- POJ 1273 USACO 93 Drainage Ditches 最大流
- 使用jacob将word转为pdf时报com.jacob.com.ComFailException: Invoke of: SaveAs ...
- 【BZOJ1660】【Usaco2006 Nov】Bad Hair Day 乱发节
- 造人论坛上关于人工智能的一些科幻想法
- http://blog.csdn.net/i_bruce/article/details/39555417
- 写Detail的接口
- 03-树3 Tree Traversals Again (25分)
- opencv笔记02-main函数使用
- 笔记---main函数及其他问题