Bzoj 3713: [pa2014] iloczyn

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.