NOIP模拟(10.23)T1 Fibonacci

Fibonacci

题目背景:

10.23 NOIP模拟T1

分析:暴力

 

最大只要109,如果你稍微观察一下就会发现,109fibonacci数少的可怜,因为每一个几乎都是上一个的两倍少一些,然后230 > 109,那么最多也不会超过30的两倍咯······实践证明有45个,那么直接暴力找出所有乘积,每次二分查找给出的x即可······

Source   

/*
	created by scarlyw
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <set>
#include <map>
#include <vector>
#include <queue>

const int MAXN = 60;
const int limit = 1000000000;

int num, cnt, t, x;
int f[MAXN], a[MAXN * MAXN];

inline void pre_work() {
	f[0] = 0, f[1] = 1;
	for (int i = 2; ; ++i) {
		f[i] = f[i - 2] + f[i - 1];
		if (f[i] > limit) {
			num = i - 1;
			break ;
		}
	}
	for (int i = 0; i <= num; ++i)
		for (int j = 0; j <= num; ++j)
			if ((long long)f[i] * (long long)f[j] <= limit) 
				a[++cnt] = f[i] * f[j];
	std::sort(a + 1, a + cnt + 1);
}

inline bool binary(int x) {
	int l = 0, r = cnt + 1;
	while (l + 1 < r) {
		int mid = l + r >> 1;
		if (a[mid] <= x) l = mid;
		else r = mid;
	}
	if (a[l] == x) return true;
	else return false;
}

inline void check(int x) {
	if (binary(x)) printf("Yes\n");
	else printf("No\n");
}

int main() {
//	freopen("fib.in", "r", stdin);
//	freopen("fib.out", "w", stdout);
	scanf("%d", &t), pre_work();
	while (t--) scanf("%d", &x), check(x);
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值