~cpp
#include <iostream>
using namespace std;
int GetFunctionY(int x)
{
//4n^2 - 8n + 5
return (4 * x * x) - (8 * x) + 5;
}
void Calculate(int& x, int& y, int remain)
{
const int PLUS_X[4] = {+0, -1, +1, +0};
const int PLUS_Y[4] = {+1, +0, +0, -1};
int endNumber = x - 1;
int gab = 0;
for (register int num = 0; num < 2; ++num)
{
for (register int j = 0 + gab; j < 2 + gab; ++j)
{
for (register int i = 0; i < endNumber; ++i)
{
--remain;
if (0 == remain)
return;
x += PLUS_X[j];
y += PLUS_Y[j];
}
}
--remain;
if (0 == remain)
return;
++y;
++endNumber;
gab = 2;
}
}
void main()
{
int inputNumber;
cin >> inputNumber;
int pointX = 1;
int pointY = 1;
register int i = 1;
if (1 == inputNumber)
{
cout << "(1, 1)" << endl;
return;
}
while(1)
{
if (inputNumber < GetFunctionY(i))
{
pointX = (i - 2) * 2 + 1;
break;
}
++i;
}
Calculate(pointX, pointY, inputNumber - GetFunctionY(i - 1) + 1);
cout << "(" << pointX << ", " << pointY << ")" << endl;
}