[Baekjoon] 1193번 분수찾기 (C++, Python)
https://www.acmicpc.net/problem/1193
1개 : 1/1 (합 = 2)
2개 : 1/2, 2/1 (합 = 3)
3개 : 3/1, 2/2, 1/3 (합 = 4)
4개 : 1/4, 2/3, 3/2, 4/1 (합 = 5)
5개 : 5/1, 4/2, 3/3, 2/4, 1/5 (합 = 6)
...
초기 시도
#include <iostream>
using namespace std;
int main() {
int n, t=0, i=1;
cin >> n;
while(n > t){
t += i;
i++;
}
if (i%2==0)
cout << (t-n)+1 << "/" << i-(t-n)-1;
else
cout << i-(t-n)-1 << "/" << (t-n)+1;
}
#include<stdio.h>
int main() {
int n,i;
scanf("%d",&n);
for(i=1;i<n;i++) {
n-=i;
}
if(i%2==0) printf("%d/%d",n,i+1-n);
else printf("%d/%d",i+1-n,n);
}
n=int(input())
i=1
while n>i:
n-=i
i+=1
if i%2==0: print(f"{n}/{i+1-n}")
else: print(f"{i-n+1}/{n}")