Count on Cantor

// http://www.spoj.com/problems/CANTON/
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
	int t;
	cin >> t;

	while (t-- >0) {
		int n;
		cin >> n;

		int approacher = 1;
		int x = 1;
		int y = 1;
		int step = 1;

		while (approacher <= n) {
			if (approacher+step > n) {
				break;
			} else {
				approacher += step;
				step++;
			}
		}
		x = step;
		int diff = n - approacher;
		int t = 0;
		if (x%2==0) {
			t = y;
			y = x;
			x = t;
			x += diff;
			y -= diff;
		} else {
			x -= diff;
			y += diff;
		}

		


		cout << "TERM "  << n << " IS " << x << "/" << y << endl;		
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章