結果
問題 | No.2 素因数ゲーム |
ユーザー | xpic |
提出日時 | 2024-11-23 23:21:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 59 ms / 5,000 ms |
コード長 | 5,265 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 55,424 KB |
最終ジャッジ日時 | 2024-11-23 23:21:23 |
合計ジャッジ時間 | 2,753 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
55,040 KB |
testcase_01 | AC | 58 ms
55,168 KB |
testcase_02 | AC | 59 ms
54,912 KB |
testcase_03 | AC | 50 ms
54,912 KB |
testcase_04 | AC | 48 ms
55,168 KB |
testcase_05 | AC | 50 ms
54,784 KB |
testcase_06 | AC | 46 ms
55,040 KB |
testcase_07 | AC | 49 ms
54,784 KB |
testcase_08 | AC | 48 ms
55,040 KB |
testcase_09 | AC | 48 ms
54,912 KB |
testcase_10 | AC | 47 ms
55,040 KB |
testcase_11 | AC | 47 ms
55,040 KB |
testcase_12 | AC | 48 ms
55,296 KB |
testcase_13 | AC | 48 ms
55,040 KB |
testcase_14 | AC | 47 ms
54,912 KB |
testcase_15 | AC | 48 ms
55,296 KB |
testcase_16 | AC | 49 ms
55,040 KB |
testcase_17 | AC | 47 ms
55,040 KB |
testcase_18 | AC | 45 ms
54,784 KB |
testcase_19 | AC | 48 ms
54,784 KB |
testcase_20 | AC | 48 ms
55,168 KB |
testcase_21 | AC | 58 ms
55,040 KB |
testcase_22 | AC | 48 ms
54,912 KB |
testcase_23 | AC | 49 ms
55,040 KB |
testcase_24 | AC | 49 ms
55,424 KB |
testcase_25 | AC | 50 ms
54,912 KB |
testcase_26 | AC | 48 ms
55,168 KB |
testcase_27 | AC | 48 ms
55,040 KB |
testcase_28 | AC | 48 ms
55,296 KB |
testcase_29 | AC | 49 ms
55,040 KB |
testcase_30 | AC | 49 ms
55,040 KB |
ソースコード
import os import sys from io import BytesIO, IOBase from random import randint, randrange from math import gcd BUFSIZE = 1 << 15 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() def miller_rabin(n, bases): m, d, s = n - 1, n - 1, 0 while d % 2 == 0: d >>= 1 s += 1 for base in bases: if n <= base: return True base = pow(base, d, n) if base == 1: continue r = 1 while base != m: if r == s: return False base = base * base % n r += 1 return True def is_prime(n): if n <= 1: return False if n <= 3: return True if n & 1 == 0: return False if n < 4759123141: return miller_rabin(n, [2, 7, 61]) if n < 18446744073709551615: return miller_rabin(n, [2, 325, 9375, 28178, 450775, 9780504, 1795265022]) d = (n - 1) >> 1 while d & 1 == 0: d >>= 1 for _ in range(100): 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 <<= 1 if y != n - 1 and t & 1 == 0: return False return True def find_prime_factor(n: int) -> int: b = n.bit_length() - 1 b = (b >> 2) << 2 m = (1 << (b >> 3)) << 1 while True: c = randrange(1, n) f = lambda a: (pow(a, 2, n) + c) % n y = 0 g = q = r = 1 while g == 1: x = y for _ in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for _ in range(min(m, r - k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 y = ys while g == 1: y = f(y) g = gcd(abs(x - y), n) if g == n: continue if is_prime(g): return g elif is_prime(n // g): return n // g else: n = g def factorize(n: int): res = [] for p in range(2, 1000): if p * p > n: break if n % p: continue while n % p == 0: n //= p res.append(p) while not is_prime(n) and n > 1: p = find_prime_factor(n) while n % p == 0: n //= p res.append(p) if n > 1: res.append(n) return sorted(res) def pe_factors(n: int): res = [] e = 0 while n % 2 == 0: n //= 2 e += 1 res.append((2, e)) for p in range(3, 1000, 2): e = 0 if p * p > n: break if n % p: continue while n % p == 0: n //= p e += 1 res.append((p, e)) while not is_prime(n) and n > 1: e = 0 p = find_prime_factor(n) while n % p == 0: n //= p e += 1 res.append((p, e)) if n > 1: res.append((n, 1)) return sorted(res) sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") N = int(input()) g = 0 for _, e in pe_factors(N): g ^= e print("Bob" if g == 0 else "Alice")