본문 바로가기

Coding/BaekJoon

B_1193

https://www.acmicpc.net/problem/1193

 

1193번: 분수찾기

첫째 줄에 X(1 ≤ X ≤ 10,000,000)가 주어진다.

www.acmicpc.net

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int level = 1;
    int nume, denom;
    int end = 1;
    if (N == 1)
        cout << level << '/' << level;
    else
    {
        for (int iter = 2; iter <= N; level++)
            iter += (level + 1);
        for (int iter = 2; iter <= level; iter++)
            end += iter;
        nume = 1;
        denom = level;
        for (int iter = end; end > N; end--)
        {
            denom--;
            nume++;
        }

        if (level % 2 != 0)
        {
            swap(denom, nume);
            cout << denom << '/' << nume;
        }

        else
            cout << denom << '/' << nume;
    }

    return 0;
}

'Coding > BaekJoon' 카테고리의 다른 글

B_24267  (0) 2023.09.26
B_10814  (0) 2023.09.26
B_18870  (0) 2023.09.26
B_2869  (0) 2023.09.26
B_2751  (0) 2023.09.26