Skip to content

Commit 3a8938d

Browse files
authored
Josephus_prblm.py
Josephus problem
1 parent e03676a commit 3a8938d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Josephus_prblm.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Josephus problem
2+
3+
# The Josephus problem is that, 100 people standing in a circle, 1 kills 2 passes the sword to 3….who survives in the end?
4+
5+
#Python_Solution ::
6+
7+
from sys import stdin,stdout
8+
9+
def Josephus_Prblm(n, k):
10+
if (n == 1):
11+
return 1
12+
else:
13+
return ((Josephus_Prblm(n - 1, k) + k-1) % n + 1)
14+
15+
for _ in range(int(stdin.readline()))
16+
17+
N = int(stdin.readline())
18+
K = int(stdin.readline())
19+
print(Josephus_Prblm(N,K))
20+
21+
22+

0 commit comments

Comments
 (0)