Advertisement
PlotnikovPhilipp

Untitled

Oct 25th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import math
  3. n = int(input())
  4. k = int(input())
  5. i = 0
  6. minimum = ''
  7. maximum = ''
  8. while i < n:
  9.     if i % 2 == 0:
  10.         minimum += '1'
  11.     else:
  12.         minimum += '0'
  13.     maximum += '1'
  14.     i += 1
  15. currentNumber = int(minimum)
  16. maximum = int(maximum)
  17. result = 0
  18. while currentNumber <= maximum:
  19.     if str(currentNumber).find('00') == -1:
  20.         result += (k-1)**(str(currentNumber).count('1'))
  21.     currentNumber =  int(bin(int('0b' + str(currentNumber), 2) + 1)[2:])
  22. print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement