무한히 큰 배열에 다음과 같이 분수들이 적혀있다.
이와 같이 나열된 분수들을 1/1 → 1/2 → 2/1 → 3/1 → 2/2 → … 과 같은 지그재그 순서로 차례대로 1번, 2번, 3번, 4번, 5번, … 분수라고 하자. X가 주어졌을 때, X번째 분수를 구하는 프로그램을 작성하시오.
분모는 1, 1 2, 1 2 3, 1 2 3 4, 1 2 3 4 5
분자는 1, 2 1, 3 2 1, 4 3 2 1, 5 4 3 2 1
namespace SongE
{
public class Program
{
static void Main(string[] args)
{
int x = int.Parse(Console.ReadLine());
int k = 1;
while(x > k)
{
x -= k;
k++;
}
int parent;
int child;
if(k % 2 == 1)
{
parent = x;
child = k + 1 - x;
}
else
{
parent = k + 1 - x;
child = x;
}
Console.WriteLine($"{child}/{parent}");
}
}
}