def supers(number):
    zeros = sum(1 for bit in range(N) if number >> bit & 1 == 0)
return 2 ** zeros

def solve(a, b, c):
    total = supers(a) + supers(b) + supers(c)
total -= supers(a | b)
total -= supers(b | c)
total -= supers(a | c)
total += supers(a | b | c)
return total
print(solve(9, 3, 6))
Считать битмаски, перечислять 0