BZOJ3713: [PA2014]Iloczyn

【传送门:BZOJ3713


简要题意:

  给出一个数,判断这个数能否是两个斐波那契数列的数的乘积


题解:

  水题,因为斐波那契数列增长得很快,所以很快就能达到10^9的级别

  所以取个50(应该取多了一点),然后O(2500)做就行了


参考代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
LL f[51];
int main()
{
    int T;
    scanf("%d",&T);
    f[0]=0;f[1]=1;
    for(int i=2;i<=50;i++) f[i]=f[i-1]+f[i-2];
    while(T--)
    {
        int x;
        scanf("%d",&x);
        if(x==0)
        {
            printf("TAK
");
            continue;
        }
        bool bk=false;
        for(int i=1;i<=50;i++)
        {
            for(int j=i;j>=1;j--)
            {
                if(f[i]*f[j]==LL(x))
                {
                    printf("TAK
");
                    bk=true;break;
                }
            }
            if(bk==true) break;
        }
        if(bk==false) printf("NIE
");
    }
    return 0;
}

 

原文地址:https://www.cnblogs.com/Never-mind/p/8687997.html