Сколько существует 16-ричных четырёхзначных чисел , в записи которых ровно одна цифра D, при этом ни одна нечётная цифра не стоит рядом с цифрой D?
Ответ:
СтатГрад Вариант ИН2510501 14 апреля 2026 – задание №8
Решение:
Решение —
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
from itertools import* k = 0 alp = '0123456789ABCDEF' for i in product(alp,repeat = 4): a = ''.join(i) if a[0] != '0' and a.count('D') == 1 : if a.count('1D') ==0 and a.count('D1') ==0 : if a.count('3D') == 0 and a.count('D3') == 0: if a.count('5D') == 0 and a.count('D5') == 0: if a.count('7D') == 0 and a.count('D7') == 0: if a.count('9D') == 0 and a.count('D9') == 0: if a.count('BD') == 0 and a.count('DB') == 0: if a.count('FD') == 0 and a.count('DF') == 0: k += 1 print(k) |
ИЛИ
|
1 2 3 4 5 6 7 8 9 |
from itertools import* k = 0 alp = '0123456789ABCDEF' for i in product(alp,repeat = 4): a = ''.join(i) if a[0] != '0' and a.count('D') == 1 : if all(a.count(f'{i}D') == 0 and a.count(f'D{i}') == 0 for i in ['1','3','5','7','9','B','F']) : k +=1 print(k) |
ИЛИ
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from itertools import * k=0 for i in product('0123456789ABCDEF', repeat = 4): a = ''.join(i) if a.count('D') != 1 or a[0]=='0': continue nechet = '13579BDF' if a[0]=='D' and a[1] not in nechet: k+=1 if a[1]=='D' and a[0] not in nechet and a[2] not in nechet: k+=1 if a[2]=='D' and a[1] not in nechet and a[3] not in nechet: k+=1 if a[3]=='D' and a[2] not in nechet: k+=1 print(k) |
Ответ: 5216
