문제 링크
https://www.acmicpc.net/problem/1158
1158번: 요세푸스 문제
첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 5,000)
www.acmicpc.net
문제

문제 풀이
n, k = map(int, input().split())
ar = [i for i in range(1, n + 1)]
index = 0
res = []
for _ in range(n):
index += k - 1
if index >= len(ar):
index = index % len(ar)
res.append(str(ar.pop(index)))
print("<",", ".join(res)[:],">", sep='')
'Algorithm > BOJ' 카테고리의 다른 글
[백준] 2609 최대공약수와 최소공배수 (파이썬 python) (0) | 2022.01.25 |
---|---|
[백준] 10430 나머지 (파이썬 python) (0) | 2022.01.25 |
[백준] 10824 네 수 (파이썬 python) (0) | 2022.01.24 |
[백준] 1406 에디터 (파이썬 python) (0) | 2022.01.24 |
[백준] 11655 ROT13 (파이썬 python) (0) | 2022.01.24 |
문제 링크
https://www.acmicpc.net/problem/1158
1158번: 요세푸스 문제
첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 5,000)
www.acmicpc.net
문제

문제 풀이
n, k = map(int, input().split())
ar = [i for i in range(1, n + 1)]
index = 0
res = []
for _ in range(n):
index += k - 1
if index >= len(ar):
index = index % len(ar)
res.append(str(ar.pop(index)))
print("<",", ".join(res)[:],">", sep='')
'Algorithm > BOJ' 카테고리의 다른 글
[백준] 2609 최대공약수와 최소공배수 (파이썬 python) (0) | 2022.01.25 |
---|---|
[백준] 10430 나머지 (파이썬 python) (0) | 2022.01.25 |
[백준] 10824 네 수 (파이썬 python) (0) | 2022.01.24 |
[백준] 1406 에디터 (파이썬 python) (0) | 2022.01.24 |
[백준] 11655 ROT13 (파이썬 python) (0) | 2022.01.24 |