結果

問題 No.3088 XOR = SUM
ユーザー 学ぶマン
提出日時 2025-04-05 11:33:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,272 ms / 2,000 ms
コード長 1,542 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 97,024 KB
最終ジャッジ日時 2025-04-05 11:34:23
合計ジャッジ時間 32,651 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 10**18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate
from heapq import heapify, heappop, heappush
def I():   return sys.stdin.readline().rstrip()
def II():  return int(sys.stdin.readline().rstrip())
def IS():  return sys.stdin.readline().rstrip().split()
def MII(): return map(int, sys.stdin.readline().rstrip().split())
def LI():  return list(sys.stdin.readline().rstrip())
def TII(): return tuple(map(int, sys.stdin.readline().rstrip().split()))
def LII(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LSI(): return list(map(str, sys.stdin.readline().rstrip().split()))
def GMI(): return list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))
def kiriage(a, b): return (a+b-1)//b
#def check(i:int, j:int): return 0 <= i < H and 0 <= j < W


def solve2(N:int):
    X = 1 << (N.bit_length() - 1)
    Y = N - X
    return X, Y

def solve(N:int):
    if N == 0:
        return 0, 0
    M = N.bit_length()

    X, Y = solve2(N)
    XY = X*Y
    X_ans, Y_ans = X, Y

    for k in range(1, M):
        num = ((N >> k) << k) - 1
        X, Y = solve2(num)
        if X*Y > XY:
            XY = X*Y
            X_ans, Y_ans = X, Y
    return X_ans, Y_ans

T = II()
ansl = []
for i in range(T):
    N = II()
    X, Y = solve(N)
    ansl.append((X, Y))

for ans in ansl:
    print(*ans)
0