~cpp
#include <iostream>
using namespace std;
int willy, direction, step, mNum;
int row, col;
void getMaja(int wNum)
{
step=1;
row=0; col=0;
if(wNum==1)
{
cout << row << " " << col<<endl;
return;
}
while(true)
{
if(3*step*step-8*step+6<=wNum && 3*step*step-7*step+5>wNum)
{
direction = 2;
mNum = wNum - (3*step*step-8*step+6);
break;
}
else if(3*step*step-7*step+5<=wNum && 3*step*step-6*step+4>wNum)
{
direction = 3;
mNum = wNum - (3*step*step-7*step+5);
break;
}
else if(3*step*step-6*step+4<=wNum && 3*step*step-5*step+3>wNum)
{
direction = 4;
mNum = wNum - (3*step*step-6*step+4);
break;
}
else if(3*step*step-5*step+3<=wNum && 3*step*step-4*step+2>wNum)
{
direction = 5;
mNum = wNum - (3*step*step-5*step+3);
break;
}
else if(3*step*step-4*step+2<=wNum && 3*step*step-3*step+1>wNum)
{
direction = 6;
mNum = wNum - (3*step*step-4*step+2);
break;
}
else if(3*step*step-3*step+1<=wNum && 3*(step+1)*(step+1)-8*(step+1)+6>wNum)
{
direction = 7;
mNum = wNum - (3*step*step-3*step+1);
break;
}
else
step++;
}
if(direction==2)
{
col=step-1;
while(mNum--)
row--;
}
else if(direction==3)
{
row=-step+1;
col=step-1;
while(mNum--)
col--;
}
else if(direction==4)
{
row=-step+1;
while(mNum--)
{
row++;
col--;
}
}
else if(direction==5)
{
col=-step+1;
while(mNum--)
row++;
}
else if(direction==6)
{
row=step-1;
col=-step+1;
while(mNum--)
col++;
}
else
{
row=step-1;
if(mNum-->=1)
{
col++;
while(mNum--)
{
row--;
col++;
}
}
}
cout << row << " " << col <<endl;
}
int main()
{
while(cin>>willy)
getMaja(willy);
return 0;
}