結果

問題 No.1450 nahco314's First Problem
ユーザー NaHCO314
提出日時 2021-03-14 20:25:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 465 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 58,752 KB
最終ジャッジ日時 2024-11-08 14:10:19
合計ジャッジ時間 3,709 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import math


def pop_count(k):
    count = 0
    for i in range(k.bit_length()):
        if k >> i & 1 == 1:
            count += 1
    return count


x = int(input())

if x != 0 and x != 1 and x != 2:
    for m in range(math.ceil(math.log2(x))+1):
        n = m ^ x
        if pop_count(n) == m:
            print(n)
            break
    else:
        print(-1)
else:
    if x == 2:
        print(-1)
    elif x == 1:
        print(3)
    else:
        print(1)
0