program RundaProbna; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes { you can add units after this }; type TDat=Array[0..1000] of Record Value,Power:Int64; End; var Max:Longint; Dat:TDat; Function FindBin(ANum:Int64):Boolean; var Left,Med,Rigth:Longint; Begin Left:=0; Rigth:=Max; Result:=False; While Left<=Rigth do Begin Med:=(Left+Rigth) div 2; If ANum=Dat[Med].Value Then Begin Result:=True; Break; End; If Dat[Med].Value<ANum Then Left:=Med+1 else Rigth:=Med-1; End; End; Procedure GenerateFibona; Begin Max:=1; Dat[0].Value :=0; Dat[0].Power :=0; Dat[1].Value :=1; Dat[1].Power :=1; repeat Max:=Max+1; Dat[Max].Value:=Dat[Max-1].Value+Dat[Max-2].Value; Dat[Max].Power:=Dat[Max].Value*Dat[Max].Value; Until Dat[Max].Value>1000000000; End; Procedure ReadTest; var Value,R:Int64; Loop:Longint; T:Boolean; Begin ReadLn(Value); T:=False; If Value in [0..1] Then T:=True Else Begin For Loop:=1 to Max do Begin R:=Value div Dat[Loop].Value; If R*Dat[Loop].Value=Value Then Begin T:=FindBin(R); If T Then Break; End; If Dat[Loop].Power>Value Then Break; End; End; If T Then WriteLn('TAK') Else WriteLn('NIE'); End; Var Count,Loop:Longint; begin GenerateFibona; ReadLn(Count); For Loop:=1 to Count do ReadTest; end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | program RundaProbna; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes { you can add units after this }; type TDat=Array[0..1000] of Record Value,Power:Int64; End; var Max:Longint; Dat:TDat; Function FindBin(ANum:Int64):Boolean; var Left,Med,Rigth:Longint; Begin Left:=0; Rigth:=Max; Result:=False; While Left<=Rigth do Begin Med:=(Left+Rigth) div 2; If ANum=Dat[Med].Value Then Begin Result:=True; Break; End; If Dat[Med].Value<ANum Then Left:=Med+1 else Rigth:=Med-1; End; End; Procedure GenerateFibona; Begin Max:=1; Dat[0].Value :=0; Dat[0].Power :=0; Dat[1].Value :=1; Dat[1].Power :=1; repeat Max:=Max+1; Dat[Max].Value:=Dat[Max-1].Value+Dat[Max-2].Value; Dat[Max].Power:=Dat[Max].Value*Dat[Max].Value; Until Dat[Max].Value>1000000000; End; Procedure ReadTest; var Value,R:Int64; Loop:Longint; T:Boolean; Begin ReadLn(Value); T:=False; If Value in [0..1] Then T:=True Else Begin For Loop:=1 to Max do Begin R:=Value div Dat[Loop].Value; If R*Dat[Loop].Value=Value Then Begin T:=FindBin(R); If T Then Break; End; If Dat[Loop].Power>Value Then Break; End; End; If T Then WriteLn('TAK') Else WriteLn('NIE'); End; Var Count,Loop:Longint; begin GenerateFibona; ReadLn(Count); For Loop:=1 to Count do ReadTest; end. |