結果
| 問題 |
No.1113 二つの整数 / Two Integers
|
| コンテスト | |
| ユーザー |
toyuzuko
|
| 提出日時 | 2020-07-18 15:29:09 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 175 ms / 1,000 ms |
| コード長 | 1,683 bytes |
| コンパイル時間 | 290 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-11-30 11:31:13 |
| 合計ジャッジ時間 | 1,950 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 15 |
ソースコード
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')
toyuzuko