結果

問題 No.3093 Please GCD
ユーザー tnodinotnodino
提出日時 2022-04-01 22:01:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,162 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 91,236 KB
平均クエリ数 213.00
最終ジャッジ日時 2024-04-30 14:02:37
合計ジャッジ時間 7,454 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
69,516 KB
testcase_01 AC 68 ms
78,080 KB
testcase_02 AC 72 ms
81,012 KB
testcase_03 AC 228 ms
89,160 KB
testcase_04 WA -
testcase_05 AC 72 ms
78,240 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 53 ms
70,784 KB
testcase_11 AC 96 ms
82,664 KB
testcase_12 AC 81 ms
79,340 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 64 ms
75,396 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
def Question(x):
    print(f'? {x}')
    return int(input())

def Answer(x):
    print(f'! {x}')
    exit()

def Operator1(x):
    S = []
    for i in range(2,int(sqrt(x))+1):
        while x % i == 0:
            S.append(i)
            x //= i
    if x >= 2:
        S.append(x)
    for bit in range(1<<len(S)):
        x = bit
        z = 1
        for i in S:
            if x & 1:
                z *= i
            x >>= 1
        P[z] = 0

def Operator2(x):
    M = x
    S = []
    for i in range(2,int(sqrt(x))+1):
        while x % i == 0:
            S.append(i)
            x //= i
    if x >= 2:
        S.append(x)
    T = []
    for bit in range(1<<len(S)):
        x = bit
        z = 1
        for i in S:
            if x & 1:
                z *= i
            x >>= 1
        T.append(z)
    for i in range(1,M+1):
        if not i in T:
            P[i] = 0

N = int(input())
P = [1] * (N+1)
for i in range(N,0,-1):
    if P[i]:
        if Question(i) == 1:
            Operator1(i)
        else:
            Operator2(i)
for i in range(N,0,-1):
    if P[i]:
        if Question(i) == i:
            Answer(i)
Answer(1)
0