zoj 2060 Fibonacci Again(fibonacci数列规律、整除3的数学特性)

题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2060

题目描述:

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

 1 /*
 2 问题 对于定义的斐波那契数列,查询第n项是否能被3整除
 3 解题思路 首先直观的解法是将前100 0000项计算出来存在表里,再查询计算,但是直接计算的话100 0000项的斐波那契数
 4 是非常大的的,基本数据类型都是不够用的
 5 利用特性“一个数的各位数字之和能被3整除,那么这个数就能被3整除”,那么对每一位先对3取余,建立一个100 0000
 6 项的表,最后查询计算就可以了
 7 另外一个投机取巧的方法是可以发现每隔三个no就会出现一个yes,那么根据结果发现规律如果n%4 == 2则是no,否则是yes
 8 */
 9 #include <vector>
10 #include <cstdio>
11 using namespace std;
12
13 int main()
14 {
15     vector<int> v;
16     int n1,n2,t,i;
17     n1=7%3;
18     n2=11%3;
19     v.push_back(n1);
20     v.push_back(n2);
21     for(i=2;i<=1000000;i++){
22         t=(n1+n2) %3;
23         v.push_back(t);
24         n1=n2;
25         n2=t;
26     }
27     int n;
28     while(scanf("%d",&n) != EOF)
29     {
30         if(v[n] % 3 == 0)
31             printf("yes\n");
32         else
33             printf("no\n");
34     }
35     /*while(scanf("%d",&n) != EOF)
36     {
37         if(n % 4 == 2)
38             printf("yes\n");
39         else
40             printf("no\n");
41     }*/
42     return 0;
43 }

原文地址:https://www.cnblogs.com/wenzhixin/p/8543690.html

时间: 2024-08-11 08:44:24

zoj 2060 Fibonacci Again(fibonacci数列规律、整除3的数学特性)的相关文章

[zoj 3774]Power of Fibonacci 数论(二次剩余 拓展欧几里得 等比数列求和)

Power of Fibonacci Time Limit: 5 Seconds      Memory Limit: 65536 KB In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the following integer sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, .

组队赛#1 解题总结 ZOJ 3798 Abs Problem (找规律+打表)

Abs Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Alice and Bob is playing a game, and this time the game is all about the absolute value! Alice has N different positive integers, and each number is not greater than N.

HDU 3117 Fibonacci Numbers(Fibonacci矩阵加速递推+公式)

题目意思很简单:求第n个Fibonacci数,如果超过八位输出前四位和后四位中间输出...,否则直接输出Fibonacci数是多少. 后四位很好求,直接矩阵加速递推对10000取余的结果就是. 前四位搜了一下:http://blog.csdn.net/xieqinghuang/article/details/7789908 Fibonacci的通项公式,对,fibonacci数是有通项公式的-- f(n)=1/sqrt(5)(((1+sqrt(5))/2)^n+((1-sqrt(5))/2)^n

zoj 3629 Treasure Hunt IV(找规律)

Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled a fromb in front of her.Alice was very excited but unfortunately not all of the treasures are real, some are fake.Now w

分圆问题:一个诡异的数列规律

问题 在圆上任取$n$个点,将每对点用直线连接起来,并规定任意三条线不能交于同一点,这些直线会将圆分割成多少份? 首先我们列出简单情况来寻找规律: 2个点将圆分成2份 3个点将圆分成4份 4个点将圆分成8份 5个点将圆分成16份 看来这个数列的规律非常明显:每增加一个点,分割的份数都将乘2.然而,当点数增加到6个的时候,分割的份数不是我们预料的32,而是31. 为了找到这个数列的通项公式,我们使用欧拉示性数公式(Euler’s Characteristic Formula)来进行推导: $$V-

【转】分圆问题:一个诡异的数列规律

问题 在圆上任取nn个点,将每对点用直线连接起来,并规定任意三条线不能交于同一点,这些直线会将圆分割成多少份? 首先我们列出简单情况来寻找规律: 2个点将圆分成2份 3个点将圆分成4份 4个点将圆分成8份 5个点将圆分成16份 看来这个数列的规律非常明显:每增加一个点,分割的份数都将乘2.然而,当点数增加到6个的时候,分割的份数不是我们预料的32,而是31. 为了找到这个数列的通项公式,我们使用欧拉示性数公式(Euler’s Characteristic Formula)来进行推导: V−E+F

ZOJ 3829 Known Notation --贪心+找规律

题意:给出一个字符串,有两种操作: 1.插入一个数字  2.交换两个字符   问最少多少步可以把该字符串变为一个后缀表达式(操作符只有*). 解法:仔细观察,发现如果数字够的话根本不用插入,数字够的最低标准为'*'的个数+1,因为最优是 '12*3*..' 这种形式,所以先判断够不够,不够就补,然后从左往右扫一遍,如果某个时刻Star+1>Num,那么从开始到这一段是不合法的,要把那个'*'与后面的一个数字交换,此时Star--,Num++.然后步数++.这样得出的结果就是最后的最小步数. 脑子

UVA11582 Colossal Fibonacci Numbers!(fibonacci序列模x的周期性)

题意:两个非负整数a,b<2^64 计算斐波拉契序列f(a^b)mod x  (x<1000) 思路:显然a^b只能用快速幂,而且还必须要取模,所以去尝试找f(n)mod x的周期 不能发现当二元组(f[i]%x,fp[i-1]%x)=(f[0]%x,f[1]%x) 的时候开始循环,所以周期为i 因为f[n]%x的余数最多只有1000种所以在f[0...n^2]以内就能找到周期 <span style="font-size:14px;">// Accepted

ZOJ 1037 &amp;&amp; HDU 1046 Gridland (找规律)

链接:click here 题意: 给你 一张图,问你从起点出发,最后回到起点的最短路程 思路: 当n,m有一者能够为偶数时,结果是n*m否者必有一条路需要斜着走,结果为n*m-1+1.41 代码: #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h