#include #include #include #include #include #include #define Test 0 typedef std::int16_t IntT; typedef std::tuple DType; typedef std::vector Stack; IntT BitCount(const IntT& v) { IntT C =0; for (IntT i = 0; i < std::numeric_limits::digits; i++) { C += (v&(1 << i)) > 0; } return C; } std::size_t MakeHoge(const IntT& N) { Stack S; IntT C = 1; IntT B = 0; S.push_back(std::make_tuple(C, 0)); while (C != N && S.size() != 0) { if (std::get<1>(S.back()) == 2) { S.pop_back(); continue; } C = std::get<0>(S.back()); B = BitCount(C); if (std::get<1>(S.back()) == 0) { C += B; } else { C -= B; } std::get<1>(S.back())++; auto rit = std::find_if(S.rbegin(), S.rend(), [&](auto& o) {return std::get<0>(o) == C; }); if (rit != S.rend()) { S.erase(rit.base(), S.rbegin().base()); } else { if (C <= N) { S.push_back(std::make_tuple(C, 0)); } } } return S.size(); } int main() { IntT R = 0; IntT N = 0; #if Test N = 5; R = MakeHoge(N); std::cout << ((R == 0) ? -1 : R) << std::endl; N = 11; R = MakeHoge(N); std::cout << ((R == 0) ? -1 : R) << std::endl; N = 4; R = MakeHoge(N); std::cout << ((R == 0) ? -1 : R) << std::endl; #else std::cin >> N; R = MakeHoge(N); std::cout << ((R == 0) ? -1 : R) << std::endl; #endif return 0; }