|
|
back to boardWhy my solution is wrong? I just use binary search. Program Task1209; { Binary Search } Var L,R,Num,N,I : Word; K,T : LongInt; Function F(Const A : LongInt) : LongInt; Begin F := A * (A + 1) Shr 1; End; BEGIN ReadLn(N); For I := 1 To N Do begin ReadLn(K); If K = 1 Then Write('1 ') Else begin L := 1; R := 40000; While R - L <> 1 Do begin Num := (R + L) Shr 1; T := F( Num ); If K > T Then L := Num Else R := Num; end; Num := (R + L) Shr 1; T := K - F( Num ); If T = 1 Then Write('1 ') Else Write('0 '); end; end; END. |
|
|