[杭電]Fibonacci Again

題目:http://acm.hdu.edu.cn/showproblem.php?pid=1021


代碼:

#include <iostream>

using namespace std;

int res[1000002];

int main()
{
	res[0] = 7;
	res[1] = 11;

	int n,i;
	int max = 2;

	while(cin>>n)
	{
		if(res[n] == 0)
		{
			for(i=max; i<=n; i++)
			{
				res[i] = (res[i-1] + res[i-2])%3;
			}
		}
		
		max = n+1;
		if(res[n]%3)
		{
			cout<<"no"<<endl;
		}
		else
		{
			cout<<"yes"<<endl;
		}
	}
	
	return 0;
}


發佈了57 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章