地址: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)==)
{
m=(m-)%+;
if(m==||m==)
cout<<"yes"<<endl;
else
cout<<"no\n";
}
return ;
}

最新文章

  1. 分布式锁1 Java常用技术方案
  2. 软件设计Tips
  3. SQL Server 自动增长过大
  4. 一个web页面的访问的过程
  5. Iframe刷新父窗口的几种方式
  6. SQL的表连接
  7. Find your present (2) (位异或)
  8. Java基础知识强化25:Java创建对象的四种方式
  9. [LeetCode] 116. Populating Next Right Pointers in Each Node 解决思路
  10. 杭电ACM2017--字符串统计
  11. linux下查询进程占用的内存方法总结
  12. Gatling实战(三)
  13. springboot之jackson的两种配置方式
  14. Java NIO- 最好文档
  15. python更新zip文件中文件
  16. 2018.09.15 poj1734Sightseeing trip(floyd求最小环)
  17. 微信小程序 --- model弹框
  18. C#多个if与if+多个else if有何不同?
  19. 【BZOJ】1951[Sdoi2010]古代猪文
  20. 洛谷P2408 不同字串个数 [后缀数组]

热门文章

  1. Web监听器导图详解
  2. 【BZOJ】3390: [Usaco2004 Dec]Bad Cowtractors牛的报复(kruskal)
  3. SQL Server跨server之间訪问
  4. ASP.NET动态添加控件一例
  5. 把登录和退出功能单独写到一个公共.py脚本,其它用例test1,test2调用公共登录,退出函数
  6. RocketMQ性能压测分析(转载)
  7. 自定义字体TextView
  8. Linq to Entity 多条件 OR查询
  9. iOS UITextView 展示html
  10. Oracle数据库模型(OLAP/OLTP)