-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoiCoSo2.py
More file actions
30 lines (30 loc) · 754 Bytes
/
DoiCoSo2.py
File metadata and controls
30 lines (30 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# T = int(input())
# for t in range(T):
# b = int(input())
# s = int(input(),2)
# if b == 2:
# print(s)
# elif b == 4:
# """
# không có hàm hệ 4
# """
# elif b == 8:
# s = oct(s)
# print(s[2::])
# else :
# s = hex(s)
# print(s[2::])
import math
f = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
t = int(input())
for i in range(t) :
n = int(input())
a = input()
n = int(math.log(n)/math.log(2))
while len(a) % n != 0 : a = '0' + a
for i in range(0, len(a), n) :
s = 0
for j in range(i, i + n):
if a[j] == '1' : s += pow(2, n - j + i - 1)
print(f[s],end = "")
print()