


기본수학 파트가 다 그렇지만, 프로그래밍이 어려운 문제가 아니라, 수학이 힘든 문제입니다.
수열로 풀어주면 됩니다. 분자와 분모의 합이 같은 그룹을 기준으로해서, 각 첫항 혹은 끝항을 기준으로 잡아서,
한 칸 전진할 때마다, 분자분모를 1씩 바꿔줍니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static int[] n(int an) {
int[] result = new int[2];
int stand;
for (int i=1; ; i++) {
stand = (i * (i+1))/2;
if (an <= stand) {
result[0] = i;
result[1] = stand - an;
break;
}
}
return result;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x = Integer.parseInt(br.readLine());
if (n(x)[0]%2 == 0) {
System.out.println((n(x)[0]-n(x)[1]) + "/" + (n(x)[1]+1));
} else {
System.out.println((n(x)[1]+1) + "/" + (n(x)[0]-n(x)[1]));
}
}
}'백준 문제풀이 > 기본수학1' 카테고리의 다른 글
| 2775. 부녀회장이 될테야 (자바, Java) (0) | 2022.09.18 |
|---|---|
| 10250. ACM 호텔 (자바, Java) (0) | 2022.09.18 |
| 2869. 달팽이는 올라가고 싶다. (자바, Java) (0) | 2022.09.18 |
| 2292. 벌집 (자바, Java) (0) | 2022.09.18 |
| 1712. 손익분기점 (자바, Java) (0) | 2022.09.18 |