結果
問題 |
No.2806 Cornflake Man
|
ユーザー |
|
提出日時 | 2024-07-13 20:13:09 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,442 bytes |
コンパイル時間 | 377 ms |
コンパイル使用メモリ | 82,312 KB |
実行使用メモリ | 139,204 KB |
最終ジャッジ日時 | 2024-07-13 20:13:14 |
合計ジャッジ時間 | 4,907 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 WA * 11 |
ソースコード
import math def is_prime(x): if x < 2: return False # 2未満に素数はない if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数 if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数 prime = 7 step = 4 while prime <= math.sqrt(x): if x % prime == 0: return False prime += step step = 6 - step return True def suspect(a, t, n): x = pow(a, t, n) n1 = n - 1 while t != n1 and x != 1 and x != n1: x = pow(x, 2, n) t <<= 1 return t & 1 or x == n1 def miller_rabin(n): if n == 2: return True if n < 2 or n % 2 == 0: return False d = (n - 1) >> 1 while d & 1 == 0: d >>= 1 check_list = (2, 7, 61) if n < 2 ** 32 else (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37) for i in check_list: if i >= n: break if not suspect(i, d, n): return False return True N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort() stA = set(A) stA.discard(0) if A[1] == 1: if M+1 == N: print(1) exit() else: print(-1) exit() primes = [] for item in A: if miller_rabin(item): primes.append(item) primes.sort() ansset = set() for p in primes: for i in range(p, M+1, p): ansset.add(i) if ansset == stA: print(len(primes)) print(*primes) else: print(-1)