1. 

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 10182 Bee Maja
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&page=show_problem&problem=1123
*
* @author Patrick Bédat
* @version 1.0, 10/27/2010
*
* Method : Simulation
* Status : Accepted
* Runtime: 0.892
*/

import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main
{

private static Map<Integer, Point> fieldCoords = new HashMap<Integer, Point>();

public static void main(String... args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(reader.readLine());
int field = Integer.parseInt(st.nextToken());
while (true)
{
if (!fieldCoords.containsKey(field));
calculateCoords(field);

Point coord = fieldCoords.get(field);

System.out.printf("%d %d%n", coord.x, coord.y);

if (reader.ready())
{
st = new StringTokenizer(reader.readLine());
field = Integer.parseInt(st.nextToken());
}
else
break;
}
}

private static void calculateCoords(int field2)
{
int radius = 1;
int x = 0;
int y = 0;

fieldCoords.put(1, new Point(0, 0));

int currentField = 2;
while (currentField <= field2)
{
y++;
fieldCoords.put(currentField++, new Point(x, y));

for (int j = 0; j < radius - 1; j++)
{
x--;
y++;
fieldCoords.put(currentField++, new Point(x, y));
}

for (int j = 0; j < radius; j++)
{
x--;
fieldCoords.put(currentField++, new Point(x, y));
}

for (int j = 0; j < radius; j++)
{
y--;
fieldCoords.put(currentField++, new Point(x, y));
}

for (int j = 0; j < radius; j++)
{
x++;
y--;
fieldCoords.put(currentField++, new Point(x, y));
}
for (int j = 0; j < radius; j++)
{
x++;
fieldCoords.put(currentField++, new Point(x, y));
}
for (int j = 0; j < radius; j++)
{
y++;
fieldCoords.put(currentField++, new Point(x, y));
}

radius++;
}
}
}