結果

問題 No.1113 二つの整数 / Two Integers
ユーザー toyuzukotoyuzuko
提出日時 2020-07-18 15:29:09
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 145 ms / 1,000 ms
コード長 1,683 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 11,112 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2023-08-20 10:02:32
合計ジャッジ時間 1,846 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
9,308 KB
testcase_01 AC 23 ms
9,264 KB
testcase_02 AC 33 ms
9,156 KB
testcase_03 AC 75 ms
9,116 KB
testcase_04 AC 56 ms
9,112 KB
testcase_05 AC 24 ms
9,116 KB
testcase_06 AC 21 ms
9,332 KB
testcase_07 AC 21 ms
9,184 KB
testcase_08 AC 22 ms
9,116 KB
testcase_09 AC 145 ms
9,180 KB
testcase_10 AC 33 ms
9,188 KB
testcase_11 AC 23 ms
9,176 KB
testcase_12 AC 31 ms
9,328 KB
testcase_13 AC 26 ms
9,320 KB
testcase_14 AC 25 ms
9,320 KB
testcase_15 AC 30 ms
9,248 KB
testcase_16 AC 27 ms
9,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from random import randint
from collections import Counter

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def miller_rabin(n, rep=100): #random.randint
    if n == 2: return True
    if n == 1 or n % 2 == 0: return False
    d = (n - 1) // 2
    while d % 2 == 0:
        d //= 2
    for k in range(rep):
        a = randint(1, n - 1)
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t *= 2
        if y != n - 1 and t % 2 == 0:
            return False
    return True

def factorize(n):
    if n == 1: return []
    res = []
    x, y = n, 2
    while y * y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1:
        res.append(x)
    return res

def pollard_rho(n): #gcd, factorize, miller_rabin
    res = []
    stack = [n]
    while stack:
        tmp = stack.pop()
        if tmp < 10**10:
            res.extend(factorize(tmp))
            continue
        if miller_rabin(tmp):
            res.append(tmp)
            continue
        seed = 1
        while True:
            x, y, d = 2, 2, 1
            f = lambda x: (x**2 + seed) % tmp
            while d == 1:
                x = f(x)
                y = f(f(y))
                d = gcd(abs(x - y), tmp)
            if d != n:
                break
            seed += 1
        stack.append(d)
        stack.append(tmp // d)
    return sorted(res)

A, B = map(int, input().split())

F = Counter(pollard_rho(A))
G = Counter(pollard_rho(B))

res = 1

for k in F.keys():
    if k in G:
        res *= (min(F[k], G[k]) + 1)

print('Even' if res % 2 == 0 else 'Odd')
0