HDU 5167

范围 内的斐波那契的数不多,求出范围内的数,再暴力枚举即可。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define  N 1000000000
__int64 foci[200];
int fc=0,cnt;
__int64 tmp[50];

void init(){
	foci[0]=0; foci[1]=1;
	fc=1;
	for(fc=2;foci[fc-1]<=N;fc++){
		foci[fc]=foci[fc-1]+foci[fc-2];
	//	cout<<foci[fc]<<endl;
	}
	fc=fc-1;
}

bool dfs(__int64 n,int pos){
	if(n==1LL) return true;
	for(int i=pos;i<=cnt;i++){
		if(n%tmp[i]==0&&dfs(n/tmp[i],i))
		return true;
	}
	return false;
}

int main(){
	init();
	int T,i;
	__int64 n;
	scanf("%d",&T);
	while(T--){
		scanf("%I64d",&n);
		if(n==0||n==1LL){
			printf("Yes\n");
			continue;
		}
		i=3; cnt=0;
		for(i;i<=fc;i++){
			if(n%foci[i]==0)
			tmp[++cnt]=foci[i];
		}
		bool flag=dfs(n,1);
		if(flag)
		printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

  

posted @ 2015-02-12 12:10  chenjunjie1994  阅读(120)  评论(0编辑  收藏  举报