AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving :: Maths - Misc
// 10161 - Ant on a Chessboard
#include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
int x, y, k, c, n;
while(cin>>n && n!=0)
{
k = ceil(sqrt(n)); // 向上取整求“最大值”
c = k * k - n; // 求坐标“差值”
if(k % 2)
{
if(c < k)
{
x = 1 + c;
y = k;
}
else
{
x = k;
y = 2 * k - c - 1;
}
}
else
{
if(c < k)
{
x = k;
y = 1 + c;
}
else
{
x = 2 * k - c - 1;
y = k;
}
}
cout << x << ' ' << y << endl;
}
return 0;
}