bzoj3713 [PA2014]Iloczyn

3713: [PA2014]Iloczyn

Time Limit: 1 Sec  Memory Limit: 128 MB

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

Tips:

  因为斐波那契数列的增长是指数级别的,所以1e9以内的数很少;

  直接暴力就可以了;

Code:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
long long n,m,f[108],tot;

int main(){
    f[1]=0; f[2]=1;
    for(int i=3;f[i-1]<=1000000000&&i<=108;i++){
        f[i]=f[i-1]+f[i-2];
        tot=i;
    }
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        long long x;
        bool boo=false;
        scanf("%lld",&x);
        for(int i=1;i<=tot;i++){
            for(int j=1;j<=tot;j++){
                if(f[i]*f[j]==x){
                    boo=true;
                    break;
                }
            }
            if(boo) break;
        }
        if(boo){
            printf("TAK
");
        }else{
            printf("NIE
");
        }
    }
}
原文地址:https://www.cnblogs.com/WQHui/p/7535480.html