首页 > 其他 > 详细

HDOJ - Fibonacci Again(斐波那契序列、数学水题)

时间:2014-03-21 01:32:49      阅读:464      评论:0      收藏:0      [点我收藏+]

方法:边加边取余,否则会溢出,long long 也会。

AC代码:

#include <iostream>    
#include <iomanip>    
#include <string>    
#include <cstring>    
#include <cstdio>    
#include <queue>    
#include <stack>    
#include <algorithm>    
#include <cmath>    
#include <ctime>

using namespace std;  

const int maxn = 1000000+0;
long long int list[maxn];

void MakeList()
{
	int i = 0;
	list[0]= 7, list[1] = 11;
	for (i = 2; i < maxn; i++)
		list[i] = (list[i-2] + list[i-1]) % 3;
}

int main()
{
#ifdef Local      
	freopen("a.in", "r", stdin);  
#endif
	int n = 0;
	MakeList();
	while(cin >> n)
	{
		if (0 == list[n] % 3)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}


HDOJ - Fibonacci Again(斐波那契序列、数学水题),布布扣,bubuko.com

HDOJ - Fibonacci Again(斐波那契序列、数学水题)

原文:http://blog.csdn.net/u013545222/article/details/21649141

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!