斐波那契数列

来源:互联网 发布:韶关市网络问政平台 编辑:程序博客网 时间:2024/06/05 07:12

QAQ
暴力处理所有<=1e9的斐波那契数
还是开long long保险

#include <cstdio>#include <cstring>#include <iostream>#include <queue>using namespace std;long long fb[99999];int cnt;void js(){    fb[0]=0;    fb[1]=1;    cnt=1;    while(1)    {        if(fb[cnt]+fb[cnt-1]>1e9)         return;        fb[++cnt]=fb[cnt-1]+fb[cnt-2];    }}int pd(long long x){    for(int i=0;i<=cnt;i++)     for(int j=0;j<=cnt;j++)      {        long long tmp=(long long) fb[i]*fb[j];        if(x==tmp) return 1;      }     return 0;}int main(){    js();    int t;    long long n;    scanf("%d",&t);    while(t--)    {        scanf("%lld",&n);        int d=pd(n);        if(d) printf("TAK\n");        else  printf("NIE\n");     }    return 0;} 
原创粉丝点击