백준 1193 c++
#include <iostream>
using namespace std;
int main(void)
{
int X, i = 2;
int temp = 1, child = 0 , parent = 0;
cin >> X;
if (X >= 1 && X <= 10000000)
{
while (1)
{
temp = temp + i;
if (temp < X)
{
i++;
}
else if (X == 1)
{
i = 0;
temp = 0;
break;
}
else//(temp >= X)
{
temp = temp - X;
i--;
break;
}
}
i = i + 1;
//child = i - temp;
//parent = i + 1 - child;
if (i % 2 == 1) //i가 홀수
{
parent = i - temp;
child = i + 1 - parent;
}
else // i가 짝수
{
child = i - temp;
parent = i + 1 - child;
}
cout << child << "/" << parent << endl;
}
else
{
;
}
return 0;
}
/*
* 1
* 3
* 6
* 10
* 15
* ......
*/
/*분자
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 .....
*/