BZOJ 3713: [PA2014]Iloczyn( 枚举 )

斐波那契数列<10^9的数很少很少...所以直接暴力枚举就行了...

-------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ; i < n ; ++i )
#define Rep( i , n ) for( int i = 0 ; i <= n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
const int N = int( 1e9 ) + 7;
 
int seq[ 1000 ] , cnt = 0;
 
int main() {
freopen( "test.in" , "r" , stdin );
seq[ 0 ] = 0 , seq[ 1 ] = 1;
for( cnt = 2 ; seq[ cnt - 1 ] < N ; cnt++ ) 
   seq[ cnt ] = seq[ cnt - 1 ] + seq[ cnt - 2 ];
int t;
cin >> t;
while( t-- ) {
long long x;
bool flag = false;
scanf( "%lld" , &x );
Rep( i , cnt ) if( seq[ i ] <= x )
   for( int j = i; j <= cnt ; j++ ) if( 1LL * seq[ i ] * seq[ j ] ==  x ) flag = true;
printf( flag ? "TAK" : "NIE" );
putchar( ' ' );
}
return 0;
}

  

------------------------------------------------------------- 

3713: [PA2014]Iloczyn

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 344  Solved: 191
[Submit][Status][Discuss]

Description

斐波那契数列的定义为:k=0或1时,F[k]=k;k>1时,F[k]=F[k-1]+F[k-2]。数列的开头几项为0,1,1,2,3,5,8,13,21,34,55,…你的任务是判断给定的数字能否被表示成两个斐波那契数的乘积。

Input

第一行包含一个整数t(1<=t<=10),表示询问数量。接下来t行,每行一个整数n_i(0<=n_i<=10^9)。

Output

输出共t行,第i行为TAK(是)或NIE(否),表示n_i能否被表示成两个斐波那契数的乘积。

Sample Input

5
5
4
12
11
10

Sample Output

TAK
TAK
NIE
NIE
TAK

HINT

Source

原文地址:https://www.cnblogs.com/JSZX11556/p/4598710.html