結果
問題 | No.774 tatyamと素数大富豪 |
ユーザー | 👑 rin204 |
提出日時 | 2022-03-25 18:42:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 287 ms / 2,000 ms |
コード長 | 1,101 bytes |
コンパイル時間 | 357 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 119,092 KB |
最終ジャッジ日時 | 2024-04-22 04:07:44 |
合計ジャッジ時間 | 3,101 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 287 ms
119,092 KB |
testcase_01 | AC | 39 ms
51,968 KB |
testcase_02 | AC | 42 ms
51,584 KB |
testcase_03 | AC | 75 ms
74,624 KB |
testcase_04 | AC | 41 ms
51,968 KB |
testcase_05 | AC | 40 ms
52,096 KB |
testcase_06 | AC | 39 ms
52,352 KB |
testcase_07 | AC | 40 ms
52,096 KB |
testcase_08 | AC | 40 ms
51,968 KB |
testcase_09 | AC | 92 ms
77,184 KB |
testcase_10 | AC | 43 ms
57,216 KB |
testcase_11 | AC | 65 ms
67,200 KB |
testcase_12 | AC | 253 ms
107,820 KB |
testcase_13 | AC | 166 ms
88,184 KB |
testcase_14 | AC | 72 ms
76,160 KB |
testcase_15 | AC | 88 ms
75,904 KB |
testcase_16 | AC | 74 ms
72,448 KB |
testcase_17 | AC | 40 ms
52,096 KB |
testcase_18 | AC | 69 ms
69,632 KB |
ソースコード
def isprime(n): if n <= 1: return False elif n == 2: return True elif n % 2 == 0: return False A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022] s = 0 d = n - 1 while d % 2 == 0: s += 1 d >>= 1 for a in A: if a % n == 0: return True x = pow(a, d, n) if x != 1: for t in range(s): if x == n - 1: break x = x * x % n else: return False return True n = int(input()) A = list(map(int, input().split())) B = [0] * n for i in range(n): if A[i] < 10: B[i] = 10 else: B[i] = 100 ans = -1 used = [False] * n memo = set() def dfs(t, x): if t == n: global ans if x > ans and isprime(x): ans = x return if x in memo: return memo.add(x) for i in range(n): if not used[i]: used[i] = True dfs(t + 1, x * B[i] + A[i]) used[i] = False dfs(0, 0) print(ans)