fork(3) download
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int T,N,Z,L,R,mid,temp;
  5. scanf("%d",&T);
  6. while(T--)
  7. {
  8. scanf("%d %d %d",&L,&R,&N);
  9. temp=R-L;
  10. int count=1;
  11. /*if(temp==1)
  12. {
  13. printf("0 0\n1\n");
  14. continue;
  15. }*/
  16. while(temp>=1 && !(L==N && R==N))
  17. {
  18. count++;
  19. printf("%d %d\n",L,R);
  20. mid=(L+R)/2;
  21. if(mid>=N)
  22. {
  23. R=mid;
  24. temp=mid-L;
  25. }
  26. else
  27. {
  28. L=mid+1;
  29. temp=R-mid-1;
  30. }
  31. }
  32. printf("%d %d\n",L,R);
  33. printf("%d\n",count);
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 2252KB
stdin
3
0 4 3
7 15 14
1 16 9
stdout
0 4
3 4
3 3
3
7 15
12 15
14 15
14 14
4
1 16
9 16
9 12
9 10
9 9
5