結果

問題 No.638 Sum of "not power of 2"
ユーザー kichirb3
提出日時 2018-03-07 08:37:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 1,000 ms
コード長 885 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-09-24 23:31:43
合計ジャッジ時間 1,128 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.638 Sum of "not power of 2"
https://yukicoder.me/problems/no/638

"""
import sys
from sys import stdin
input = stdin.readline


def is_valid(a, b, prohibits):
    if a < 1 or b < 1:
        return False
    if a in prohibits or b in prohibits:
        return False
    return True


def solve(N):
    prohibits = set([])
    for i in range(64):
        prohibits.add(2**i)

    ans = -1
    for i in range(64):
        t = 2**i

        a = t - 1
        b = N - a
        if is_valid(a, b, prohibits):
            ans = a
            break

        a = t + 1
        b = N - a
        if is_valid(a, b, prohibits):
            ans = a
            break

    return ans


def main(args):
    N = int(input())
    ans = solve(N)
    if ans != -1:
        print(ans, N - ans)
    else:
        print(-1)


if __name__ == '__main__':
    main(sys.argv[1:])
0