File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 1
1
// Authored by : SciEm
2
2
// Co-authored by : -
3
- // http://boj.kr/037f3a0f8454498d8b609d819fd67398
3
+ // http://boj.kr/4786afbccbb148098938f248823abd35
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
6
7
7
int main () {
8
8
ios::sync_with_stdio (0 );
9
9
cin.tie (0 );
10
10
11
- int x; cin >> x;
11
+ int x;
12
+ cin >> x;
12
13
14
+ // x에서 1 2 3 ...을 빼다보면 찾는 수가 i 번째 군의 x 번째 수가 된다.
13
15
int i = 1 ;
14
- while (x > i) x -= i++;
16
+ while (x > i) {
17
+ x -= i;
18
+ i++;
19
+ }
15
20
16
21
int nume = x;
17
22
int deno = i + 1 - x;
18
- if (i % 2 ) swap (nume, deno);
23
+ if (i % 2 ) swap (nume, deno); // 홀수 번째 군의 순서가 문제와 반대이므로 뒤집는다.
19
24
cout << nume << ' /' << deno;
20
25
}
26
+ /*
27
+ 수열을 (1/1) (1/2 2/1) (1/3 2/2 3/1) ... 과 같이 묶으면 i번째 군의 개수는
28
+ i개 이고 분자와 분모의 합이 i + 1로 일정함을 알 수 있다.
29
+ */
You can’t perform that action at this time.
0 commit comments