結果
問題 | No.2 素因数ゲーム |
ユーザー | rpy3cpp |
提出日時 | 2015-03-25 23:55:57 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 31 ms / 5,000 ms |
コード長 | 1,346 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-06-07 23:45:08 |
合計ジャッジ時間 | 1,870 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,880 KB |
testcase_01 | AC | 29 ms
10,880 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 28 ms
11,008 KB |
testcase_04 | AC | 30 ms
11,008 KB |
testcase_05 | AC | 28 ms
10,880 KB |
testcase_06 | AC | 29 ms
10,880 KB |
testcase_07 | AC | 28 ms
10,880 KB |
testcase_08 | AC | 28 ms
10,880 KB |
testcase_09 | AC | 29 ms
10,880 KB |
testcase_10 | AC | 28 ms
10,880 KB |
testcase_11 | AC | 28 ms
11,008 KB |
testcase_12 | AC | 28 ms
10,880 KB |
testcase_13 | AC | 29 ms
11,008 KB |
testcase_14 | AC | 27 ms
10,880 KB |
testcase_15 | AC | 29 ms
10,880 KB |
testcase_16 | AC | 29 ms
11,008 KB |
testcase_17 | AC | 30 ms
10,880 KB |
testcase_18 | AC | 30 ms
10,880 KB |
testcase_19 | AC | 30 ms
11,008 KB |
testcase_20 | AC | 30 ms
10,880 KB |
testcase_21 | AC | 30 ms
11,008 KB |
testcase_22 | AC | 28 ms
10,880 KB |
testcase_23 | AC | 28 ms
10,880 KB |
testcase_24 | AC | 29 ms
11,008 KB |
testcase_25 | AC | 28 ms
10,880 KB |
testcase_26 | AC | 28 ms
10,880 KB |
testcase_27 | AC | 28 ms
10,880 KB |
testcase_28 | AC | 29 ms
11,008 KB |
testcase_29 | AC | 28 ms
11,008 KB |
testcase_30 | AC | 28 ms
10,880 KB |
ソースコード
import math import collections def factorize(n): ''' returns a list of prime factors of n. ex. factorize(24) = [2, 2, 2, 3] source: Rossetta code: prime factorization (slightly modified) http://rosettacode.org/wiki/Prime_decomposition#Python:_Using_floating_point ''' step = lambda x: 1 + (x<<2) - ((x>>1)<<1) maxq = int(math.floor(math.sqrt(n))) d = 1 q = n % 2 == 0 and 2 or 3 while q <= maxq and n % q != 0: q = step(d) d += 1 return q <= maxq and [q] + factorize(n//q) or [n] def solve(N): facs = factorize(N) facs = collections.Counter(facs) facs = list(facs.values()) facs.sort() return f(facs) memo = dict() def f(facs): global memo facs.sort() if facs[0] == 0: facs = facs[1:] facs_tuple = tuple(facs) if facs_tuple in memo: return memo[facs_tuple] if len(facs_tuple) == 1: memo[facs_tuple] = True return True for i, fac in enumerate(facs_tuple): for j in range(fac): new_facs = facs[:i] + [j] + facs[i + 1:] if not f(new_facs): memo[facs_tuple] = True return True memo[facs_tuple] = False return False if __name__ == '__main__': N = int(input()) if solve(N): print('Alice') else: print('Bob')