UVA – 10161 – Ant on a Chessboard

#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
#define sqr(ZZ) (ZZ)*(ZZ)

int main() {
	long long x, y, t, d;
	while ((cin >> t) && t) {
		x = y = ceil(sqrt(t));
		d =  (x%2 ? 1 : -1)*(t - (int)(sqr(x-1) + x));

		x -= d > 0 ? d : 0;
		y += d < 0 ? d : 0;

		cout << x << " " << y << endl;
	}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: