Advertisement
erfanul007

Light OJ 1008

Dec 29th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5. long long int t,n,i,j,r,c,x,y,sx,sy,a,b;
  6. scanf("%lld",&t);
  7. for(i=1;i<=t;i++){
  8. scanf("%lld",&n);
  9. x=sqrt(n);
  10. y=x+1;
  11. sx=x*x;
  12. sy=y*y;
  13. if(sx==n){
  14. if(x%2==0){
  15. r=x;
  16. c=1;
  17. }
  18. else{
  19. r=1;
  20. c=x;
  21. }
  22. }
  23. else{
  24. a=n-sx;
  25. b=sy-n;
  26. if(a>b){
  27. if(y%2==0){
  28. r=y;
  29. c=sy-n+1;
  30. }
  31. else{
  32. r=sy-n+1;
  33. c=y;
  34. }
  35.  
  36. }
  37. else{
  38. if(x%2==0){
  39. r=x+1;
  40. c=n-sx;
  41. }
  42. else{
  43. r=n-sx;
  44. c=x+1;
  45. }
  46. }
  47. }
  48. printf("Case %lld: %lld %lld\n",i,r,c);
  49. }
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement