Description
The Fibonacci sequence is defined as: K = 0 or 1, F [k] = K; k> 1, F [k] = f [k-1] + F [K-2]. The first number of columns is 0, 1, 2, 3, 5, 8, 13, 55 ,... Your task is to determine whether a given number can be expressed as the product of two Fibonacci numbers. Input
The first line contains an integer T (1 <=t <= 10), indicating the number of queries. In the next t row, each row has an integer n_ I (0 <= n_ I <= 10 ^ 9 ). Output
Output t rows in total. The I behavior Tak (yes) Or Nie (NO) indicates whether n_ I can be expressed as the product of two Fibonacci numbers.
Question:
Because f [44]> 1e9. So we can calculate the product of two pairs and enumerate them.
Code:
#include<cstdio>#include<cstring>#include<algorithm>#include<set>//by zrt//problem:using namespace std;int f[46];set<int> s;int main(){ #ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif f[0]=0;f[1]=1; for(int i=2;i<=45;i++){ f[i]=f[i-1]+f[i-2]; } int MAX=1e9; for(int i=0;i<=45;i++) s.insert(f[i]); for(int i=3;i<=45;i++){ for(int j=i;j<=45;j++){ if(f[i]*1LL*f[j]<=MAX){ s.insert(f[i]*f[j]); } } } int t,x; scanf("%d",&t); while(t--){ scanf("%d",&x); if(s.count(x)){ puts("TAK"); }else{ puts("NIE"); } } return 0;}
Bzoj 3713: [pa2014] iloczyn