結果

問題 No.638 Sum of "not power of 2"
ユーザー kichirb3kichirb3
提出日時 2018-03-07 08:37:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 33 ms / 1,000 ms
コード長 885 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 11,852 KB
実行使用メモリ 10,000 KB
最終ジャッジ日時 2023-10-25 04:06:20
合計ジャッジ時間 1,265 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,000 KB
testcase_01 AC 33 ms
10,000 KB
testcase_02 AC 33 ms
10,000 KB
testcase_03 AC 31 ms
10,000 KB
testcase_04 AC 29 ms
10,000 KB
testcase_05 AC 30 ms
10,000 KB
testcase_06 AC 30 ms
10,000 KB
testcase_07 AC 30 ms
10,000 KB
testcase_08 AC 30 ms
10,000 KB
testcase_09 AC 30 ms
10,000 KB
testcase_10 AC 29 ms
10,000 KB
testcase_11 AC 30 ms
10,000 KB
testcase_12 AC 30 ms
10,000 KB
testcase_13 AC 30 ms
10,000 KB
権限があれば一括ダウンロードができます

ソースコード

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