[ACM]Q264: Count on Cantor
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q264
{
class Program
{
static private int _n; static private bool _ntof; static int _numerator, _denominator,t1,t2;
static void Main(string[] args)
{
for (; ; )
{
labeln: Console.Write("N>>>");
_ntof = int.TryParse(Console.ReadLine(), out _n);
if (!_ntof) goto labeln;
for (t2 = 1, t1 = _n; t1 > t2; t2++) t1 = t1 - t2;
if (t2 % 2 == 1) _numerator = t2 - t1 + 1;
else _numerator = t1;
_denominator = t2 + 1 - _numerator;
Console.WriteLine("TERM {0} IS {1}/{2}", _n, _numerator, _denominator);
}
}
}
}