maxim_shlyahtin

16

Feb 1st, 2022 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. def f(n: int):
  2.     if n == 0:
  3.         return 0
  4.     elif n > 0 and n % 2 == 0:
  5.         return f(n // 2)
  6.     elif n > 0 and n % 2 == 1:
  7.         return f(n - 1) + 1
  8.  
  9.  
  10. count = 0
  11. for n in range(1, 501):
  12.     if f(n) == 8:
  13.         count += 1
  14. print(count)
Add Comment
Please, Sign In to add comment