package main import ( "fmt" ) func main() { solve() } func solve(){ var N, x uint64 fmt.Scan(&N) x = 1 count := 0 for { x = x+popcount(x) count += 1 if x >= N{ break } if count > 100000000{ break } } if x == N{ fmt.Println(count+1) }else{ fmt.Println("-1") } } func popcount(x uint64) uint64 { x = (x & 0x5555555555555555) + ((x & 0xAAAAAAAAAAAAAAAA) >> 1) x = (x & 0x3333333333333333) + ((x & 0xCCCCCCCCCCCCCCCC) >> 2) x = (x & 0x0F0F0F0F0F0F0F0F) + ((x & 0xF0F0F0F0F0F0F0F0) >> 4) x = (x & 0x00ff00ff00ff00ff) + ((x & 0xff00ff00ff00ff00) >> 8) x = (x & 0x0000ffff0000ffff) + ((x & 0xffff0000ffff0000) >> 16) x = (x & 0x00000000ffffffff) + ((x & 0xffffffff00000000) >> 32) return x }