fork download
  1. open System
  2.  
  3. let a = Console.ReadLine().Split()
  4. let n = int64(a.[1]) - 1L
  5. let h = int(a.[0]) - 1
  6.  
  7. let f (h:int) (n:int64)=
  8. let mutable i = h
  9. let mutable mv = 0L
  10. let mutable ans = 0L
  11. let mutable tmp = 0L
  12. let mutable temp = 0L
  13. while i >= 0 do
  14. if ((n &&& (1L <<< i)) = 0L) then
  15. temp <- 0L;
  16. else
  17. temp <- 1L;
  18. if (mv <> temp) then
  19. ans <- ans + ((1L <<< (i + 1)) - 1L);
  20. mv <- mv ^^^ 1L
  21. mv <- mv ^^^ 1L
  22. ans <- ans + 1L
  23. i <- i - 1
  24. printfn "%i" ans
  25.  
  26. f h n
Success #stdin #stdout 0.08s 24712KB
stdin
3 4
stdout
4