12380 | 2024-12-15 12:19:58 | Firesloth28 | 2015. október | python3 | Accepted | 16ms | 3320 KiB |
from sys import stdin, stdout
def factorial(x):
res = 1
for i in range(2, x + 1):
res *= i
return res
def main():
n, k = map(int, stdin.readline().split())
numbers = list(range(1, n + 1))
divisor = n - 1
i = k - 1
while len(numbers) > 1:
fact = factorial(divisor)
group = i // fact
stdout.write(str(numbers[group]) + " ")
numbers.pop(group)
divisor -= 1
i = i % fact
stdout.write(str(numbers[0]))
main()
1 2 4 3
Expected output:1 2 4 3
Checker output:ok 4 number(s): "1 2 4 3"
5 3 2 4 1
Expected output:5 3 2 4 1
Checker output:ok 5 number(s): "5 3 2 4 1"
1
Expected output:1
Checker output:ok 1 number(s): "1"
1 8 3 5 7 4 2 6 9
Expected output:1 8 3 5 7 4 2 6 9
Checker output:ok 9 numbers
1 8 10 2 3 12 4 6 7 5 9 11
Expected output:1 8 10 2 3 12 4 6 7 5 9 11
Checker output:ok 12 numbers
7 3 1 5 8 9 10 11 2 6 4
Expected output:7 3 1 5 8 9 10 11 2 6 4
Checker output:ok 11 numbers
2 1
Expected output:2 1
Checker output:ok 2 number(s): "2 1"
6 3 8 2 5 4 10 11 7 1 9
Expected output:6 3 8 2 5 4 10 11 7 1 9
Checker output:ok 11 numbers
4 5 2 1 7 6 3
Expected output:4 5 2 1 7 6 3
Checker output:ok 7 numbers
10 2 4 1 5 8 3 9 7 6
Expected output:10 2 4 1 5 8 3 9 7 6
Checker output:ok 10 numbers
1
Expected output:1
Checker output:ok 1 number(s): "1"
2 5 14 12 8 4 11 6 13 9 1 10 3 7
Expected output:2 5 14 12 8 4 11 6 13 9 1 10 3 7
Checker output:ok 14 numbers
3 2 1
Expected output:3 2 1
Checker output:ok 3 number(s): "3 2 1"
1 4 3 6 2 5
Expected output:1 4 3 6 2 5
Checker output:ok 6 numbers
1
Expected output:1
Checker output:ok 1 number(s): "1"
14 13 12 11 10 9 8 7 6 5 4 3 2 1
Expected output:14 13 12 11 10 9 8 7 6 5 4 3 2 1
Checker output:ok 14 numbers
7 14 13 12 11 10 9 8 6 5 4 3 2 1
Expected output:7 14 13 12 11 10 9 8 6 5 4 3 2 1
Checker output:ok 14 numbers