Advertisement
Plabon_dutta

UVA 10161 Ant on Chess broad

May 28th, 2021
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include<cmath>
  2. #include<cstdio>
  3.  
  4. int n, x, y;
  5.  
  6. int main() {
  7.     for(;;) {
  8.         scanf("%d", &n);
  9.         if(n == 0) break;
  10.  
  11.         int root = ceil(sqrt(n));
  12.         int c = root * root - root + 1;
  13.         x = y = root;
  14.  
  15.         if(root % 2 == 0) {
  16.             if(n > c) y -= n - c;
  17.             else x -= c - n;
  18.         } else {
  19.             if(n > c) x -= n - c;
  20.             else y -= c - n;
  21.         }
  22.  
  23.         printf("%d %d\n", x, y);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement