fork download
  1. program countturns;
  2.  
  3. var
  4. K, N, T, test, r, P : LongInt;
  5. S : AnsiString;
  6.  
  7. begin
  8. {
  9.   uncomment the two following lines if you want to read/write from files
  10.   assign(input, 'input.txt'); reset(input);
  11.   assign(output, 'output.txt'); rewrite(output);
  12. }
  13.  
  14. ReadLn(T);
  15. for test:=1 to T do begin
  16. ReadLn(N, K);
  17.  
  18. S := '';
  19.  
  20. if K mod 2 =0 then
  21. begin
  22. P:=(K*(K+1)) div 2;
  23. r:=(N-1) mod P +1;
  24. if (r<=P) and (r>=P-K+1) then S:='Alice'
  25. else S:='Bob';
  26. end
  27. else
  28. begin
  29. P:=K*(K+1);
  30. r:=(N-1) mod P +1;
  31. if (r<=((K*K)+1) div 2 +K-1) and (r>=((K*K)+1) div 2) or ((r<=P) and (r>=P-K+1)) then S:='Alice'
  32. else S:='Bob';
  33. end;
  34.  
  35. WriteLn(S);
  36. end;
  37.  
  38. end.
Success #stdin #stdout 0s 544KB
stdin
3
3 2
4 1
47 7
stdout
Alice
Alice
Bob