hdu 1021 Fibonacci Again

本文介绍了一种变种斐波那契数列的计算方法,该数列从F(0)=7和F(1)=11开始,并遵循常规斐波那契数列的递推公式。通过取模运算简化计算过程,实现了快速判断F(n)是否能被3整除的方法。

斐波那契的递推;

有规律,但是我打表过了;

f[0]=7;

f[1]=11;   

实际对他们%3 就是 f[0]=1. f[1]=2;正规的斐波那契了;

 则有n>2  f[n]=(f[n-1]+f[n-2])%3;

递推出斐波那契数列;

则问输入n,f[n]%3==0 yes . 否则 no;

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

#include <bits/stdc++.h>
using namespace std ;
long long dp[10000000];
int main()
{
	dp[0]=7%3;
	dp[1]=11%3;
	for(int i = 2;i<=1000000;i++)
	{
		dp[i]=(dp[i-1]+dp[i-2])%3;
	}
	int n ;
	while(cin>>n)
	{
		if(dp[n]%3==0) printf("yes\n");
		else printf("no\n");
		}	
		return 0 ;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kelisita

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值