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]<=A[X] Then A begin the iflef[x]=0 ThenLef[x]:=yElseins (lef[x],y); + ifFIX[LEF[X]]<FIX[X] ThenRT (x); - End $ Else $ begin - ifrig[x]=0 ThenRig[x]:=yElseins (rig[x],y); - ifFIX[RIG[X]]<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<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