U E D R , A S I H C RSS

Ant OnAChessboard/김상섭

4300966 2006-02-01 17:20:17 Accepted 0.002 Minimum 28565 C++ 10161 - Ant on a Chessboard


~cpp
#include <iostream>
#include <math.h>
using namespace std;

void process(int num)
{

	int level, temp, x, y;
	
	level = ceil(sqrt(num));
	temp = num - (level-1)*(level-1);
	if(temp > level)
	{
		x = level;
		y = 2*level - temp;
	}
	else
	{
		y = level;
		x = temp;
	}
	
	if(level % 2 == 0)
		cout << x << " " << y << endl;
	else
		cout << y << " " << x << endl;
}
int main()
{
	int num;
	cin >> num;
	while(num)
	{
		process(num);
		cin >> num;
	}
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:30
Processing time 0.0097 sec