比赛 20111107 评测结果 TTTTTTTTTT
题目名称 产生01串 最终得分 0
用户昵称 Citron酱 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2011-11-07 10:40:58
显示代码纯文本
#include <fstream>

#define I_F "infinit.in"
#define O_F "infinit.out"

const unsigned long long M=2223372036;
const unsigned short N=200;

unsigned long long s[N]={1,2};
unsigned short n;

void GetFibonacci();
unsigned long long Fib(const unsigned long long);

int main()
{
	GetFibonacci();
	std::ifstream fin(I_F);
	std::ofstream fout(O_F);
	int q;
	unsigned long long a,b;
	for (fin>>q; q>0; q--)
	{
		fin>>a>>b;
		fout<<Fib(b)-Fib(a-1)<<std::endl;
	}
	fin.close();
	fout.close();
	return 0;
}

void GetFibonacci()
{
	for (n=1; s[n]<=M; n++)
		s[n+1]=s[n-1]+s[n];
}

unsigned long long Fib(const unsigned long long x)
{
	unsigned short t;
	for (t=0; (t<n)&&(s[t]<x); t++);
	if (s[t]==x)
		return s[t-1];
	return s[t-1]+Fib(x-s[t]);
}