Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
839 B
2
Indexable
Never
def slovag(n):
    if n == 0:
        yield ''
    elif n == 1:
        
        
        yield '1'
        yield '0'
    else:
        for el in slovag(n-1):
            
            
               # if el[-1] != '0':
            if '000' not in el + '0':
                yield el+'0'
                yield el+'1'


def convert_from_binary_to_decimal(binary_num):
    cislo = 0
    index = 0
    for i in reversed(range(len(binary_num))):
        cislo += (2 ** index) * (int(binary_num[i]) % 2)
        index += 1
    return cislo
def sucetPrvychk(k, n):
    res = 0
    num_of_added = 0

    for slovo in slovag(n):    

        
        res += convert_from_binary_to_decimal(slovo)
        num_of_added += 1
        if num_of_added == k:
            break
            
    return res % (10**9 + 7)