hdu 1021

Fibonacci Again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 36384    Accepted Submission(s): 17575

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

Author

Leojay

找规律题:

f(n)依次是7,11,18,29,47,76,123,199,

322,521,843,1364,2207。3571,5778,9349

除以三时候各自是 1,2,0,2,2,1,0,1

1,2,0,2,2,1,0,1

周期是八 一般的计算方法就会超时

<span style="font-size:24px;">#include<stdio.h>
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		if(n%4==2)
		printf("yes\n");
		else
		printf("no\n");
	}
	return 0;
}</span>
时间: 2024-10-05 23:36:55

hdu 1021的相关文章

HDU 1021[Fibonacci Again]规律

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1021 题目大意:首两项为7,11的斐波那契数列.若第n项能被3整除,输出yes,否则输出no 关键思想:模三加法情况有限,找规律. 代码如下: #include <iostream> using namespace std; int main(){ int n; while(cin>>n) if(n%8==2||n%8==6)cout<<"yes"<

hdu 1021 Fibonacci Again(变形的斐波那契)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 70782    Accepted Submission(s): 32417 Problem Description There are another ki

HDU 1021.Fibonacci Again【规律】【不可直接求】【8月18】

Fibonacci Again 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 &q

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 ......... 显然循环了 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int n; 6 while(cin>>n){ 7 if(n%4==2) cout<<"yes"<<endl; 8 else

HDU 1021 Fibonacci Again 数学题

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

hdu 1021 斐波那契2,找规律

背景:暴力必定超数据结构范围,因为斐波那契类型数列,成指数形式爆炸增长.故写了数据发现取余30不影响结果. 学习:1.数论类题可以写出几组数据找规律,猜结论. 我的代码: #include<stdio.h> int str[1000009] = { 7, 11 }; int main() { int n; for (int i = 2; i <=1000000; i++){ str[i] = (str[i - 1] + str[i - 2])% 30; } while (scanf(&q

hdu 1021 Fibonacci Again 找规律

Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51448    Accepted Submission(s): 24346 Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n)

杭电 HDU 1021 Fibonacci Again

Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 41156    Accepted Submission(s): 19705 Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n)

HDU 1021(斐波那契数与因子3 **)

题意是说在给定的一种满足每一项等于前两项之和的数列中,判断第 n 项的数字是否为 3 的倍数. 斐波那契数在到第四十多位的时候就会超出 int 存储范围,但是题目问的是是否为 3 的倍数,也就是模 3 值为 0 ,考虑到余数只有0,1,2,而且每项由前两项求和得到,也就是说余数一定会出现循环的规律,从首项开始,前 8 项模 3 的结果是:1 2 0 2 2 1 0 1,接下来的两项模 3 的结果仍是 1 2 ,那么整个序列就呈现出以 8 为周期的特点,只要模 8 的结果为 3 或者 7 就输出