标签:
Problem Description:
题意:判断一个数n是不是Fibonacci序列中数的乘积(可以是同一个数)。
#include<stdio.h> #include<string.h> #include<queue> #include<math.h> #include<stdlib.h> #include<algorithm> using namespace std; const int N=1e6+10; const int INF=0x3f3f3f3f; const int MOD=1e9; typedef long long LL; LL n, a[60]; int k, flag; void Solve() ///打表,并找到满足题意的最大的Fibonacci数的下标k { int i; a[0] = 0; a[1] = 1; for (i = 2; i <= 50; i++) { a[i] = a[i-1]+a[i-2]; if (a[i] >= MOD) { if (a[i] > MOD) i--; k = i; break; } } } void DFS(int num, LL m) { int i; if (m == 1) flag = 1; if (flag == 1) return ; if (num < 3) return ; if (m % a[num] == 0) DFS(num, m/a[num]); DFS(num-1, m); } int main () { int T; Solve(); scanf("%d", &T); while (T--) { scanf("%lld", &n); flag = 0; if (n == 0) { printf("Yes\n"); continue; } DFS(k, n); if (flag == 1) printf("Yes\n"); else printf("No\n"); } return 0; }
HDU 5167 Fibonacci(BestCoder Round #28)
标签:
原文地址:http://www.cnblogs.com/syhandll/p/4977355.html