3713: [Pa2014]iloczyn

Source: Internet
Author: User

3713: [Pa2014]iloczyn time limit:1 Sec Memory limit:128 MB
submit:327 solved:181
[Submit] [Status] [Discuss] Description

The Fibonacci sequence is defined as: k=0 or 1 o'clock, f[k]=k;k>1, f[k]=f[k-1]+f[k-2]. The beginning of the sequence is 0,1,1,2,3,5,8,13,21,34,55,... Your task is to determine whether a given number can be represented as a product of two Fibonacci numbers.

Input

The first line contains an integer t (1<=t<=10), which indicates the number of queries. Next T line, one integer per line n_i (0<=n_i<=10^9).

Output

Output a total of T-lines, I act tak (yes) or NIE (no), indicating whether the n_i can be expressed as a product of two Fibonacci numbers.

Sample Input5
5
4
12
11
TenSample OutputTAK
TAK
NIE
NIE
TAKHINT Source

Acknowledgement JCVB

Puzzle: At first I thought about how to preprocess, but later found that it seems to be a (\log M \) Number (although obviously not so little, but in fact not more than 60 appearance) in the \ ({10}^{9} \), and then \ (T \leq 10 \), Brute force enumeration easy water over (PS: Ah oh tease than I also used a balance tree to maintain, but later only thought looks like two points to find is enough =)

1/**************************************************************2Problem:37133 User:hansbug4 language:pascal5 result:accepted6Time:0Ms7Memory:244KB8****************************************************************/9  Ten var OneA:Array[0.. +] ofInt64; ALef,rig,fix:Array[0.. +] ofLongint; - I,j,k,l,m,n,head,t:longint; - A1:int64; the procedureRtvarx:longint); -           varF,l:longint; -           begin -                if(x=0)or(lef[x]=0) Thenexit; +f:=x;l:=Lef[x]; -lef[f]:=Rig[l]; +rig[l]:=F; Ax:=l; at           End; - procedureLtvarx:longint); -           varF,r:longint; -           begin -                if(x=0)or(rig[x]=0) Thenexit; -f:=x;r:=Rig[x]; inrig[f]:=Lef[r]; -lef[r]:=F; tox:=R; +           End; - procedureInsvarx:longint;y:longint); the           begin *                ifx=0  Then $                   beginPanax Notoginsengx:=y; - exit; the                   End; +                ifA[Y]&LT;=A[X] Then A                   begin the                        iflef[x]=0  ThenLef[x]:=yElseins (lef[x],y); +                        ifFIX[LEF[X]]&LT;FIX[X] ThenRT (x); -                   End $                Else $                    begin -                         ifrig[x]=0  ThenRig[x]:=yElseins (rig[x],y); -                         ifFIX[RIG[X]]&LT;FIX[X] ThenLT (x); the                    End; -           End;Wuyi functionCheck (X:longint;y:int64): boolean; the          begin -               ifx=0  Thenexit (false); Wu               ifA[x]=y Thenexit (true); -               ifY&LT;A[X] ThenExit (check (lef[x],y))Elseexit (check (rig[x],y)); About          End; $ begin -a[1]:=0; a[2]:=1; head:=0; randomize; -       fori:=3  to  -  Doa[i]:=a[i-1]+a[i-2]; -       fori:=1  to  -  Do A          begin +lef[i]:=0; rig[i]:=0; fix[i]:=random (maxlongint); the ins (head,i); -          End; $ readln (t); the       whileT>0  Do the            begin the READLN (A1); the                 ifa1=0  ThenWriteln ('TAK')Else -                    begin inj:=0; the                          fori:=2  to  -  Do the                             begin About                                  ifA[i]>a1 ThenBreak ; the                                  if(A1MoDA[i]) <>0  Thencontinue; the                                  ifCheck (HEAD,A1DivA[i]) Then the                                     begin +j:=1; Writeln ('TAK'); - Break ; the                                     End;Bayi                             End; the                         ifj=0  ThenWriteln ('NIE'); the                    End; - Dec (t); -            End; the Readln; the End.

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.