結果
問題 | No.308 素数は通れません |
ユーザー | tjake |
提出日時 | 2015-12-01 03:18:52 |
言語 | Python2 (2.7.18) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,262 bytes |
コンパイル時間 | 554 ms |
コンパイル使用メモリ | 6,944 KB |
実行使用メモリ | 7,552 KB |
最終ジャッジ日時 | 2024-09-14 06:23:34 |
合計ジャッジ時間 | 4,795 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
7,552 KB |
testcase_01 | AC | 17 ms
7,296 KB |
testcase_02 | AC | 16 ms
7,424 KB |
testcase_03 | AC | 17 ms
7,296 KB |
testcase_04 | AC | 17 ms
7,552 KB |
testcase_05 | AC | 16 ms
7,296 KB |
testcase_06 | AC | 17 ms
7,424 KB |
testcase_07 | AC | 16 ms
7,552 KB |
testcase_08 | AC | 17 ms
7,424 KB |
testcase_09 | AC | 17 ms
7,424 KB |
testcase_10 | AC | 16 ms
7,424 KB |
testcase_11 | AC | 17 ms
7,424 KB |
testcase_12 | AC | 17 ms
7,424 KB |
testcase_13 | AC | 17 ms
7,424 KB |
testcase_14 | AC | 16 ms
7,424 KB |
testcase_15 | AC | 17 ms
7,424 KB |
testcase_16 | AC | 16 ms
7,424 KB |
testcase_17 | AC | 17 ms
7,424 KB |
testcase_18 | AC | 17 ms
7,296 KB |
testcase_19 | AC | 17 ms
7,424 KB |
testcase_20 | AC | 16 ms
7,552 KB |
testcase_21 | AC | 17 ms
7,424 KB |
testcase_22 | AC | 16 ms
7,424 KB |
testcase_23 | AC | 16 ms
7,552 KB |
testcase_24 | AC | 16 ms
7,296 KB |
testcase_25 | AC | 16 ms
7,424 KB |
testcase_26 | AC | 17 ms
7,424 KB |
testcase_27 | AC | 16 ms
7,424 KB |
testcase_28 | AC | 16 ms
7,424 KB |
testcase_29 | AC | 17 ms
7,424 KB |
testcase_30 | AC | 17 ms
7,424 KB |
testcase_31 | AC | 17 ms
7,552 KB |
testcase_32 | AC | 18 ms
7,296 KB |
testcase_33 | AC | 17 ms
7,424 KB |
testcase_34 | AC | 17 ms
7,424 KB |
testcase_35 | AC | 17 ms
7,424 KB |
testcase_36 | AC | 16 ms
7,424 KB |
testcase_37 | AC | 17 ms
7,552 KB |
testcase_38 | AC | 17 ms
7,424 KB |
testcase_39 | AC | 19 ms
7,296 KB |
testcase_40 | AC | 18 ms
7,424 KB |
testcase_41 | AC | 17 ms
7,424 KB |
testcase_42 | AC | 17 ms
7,296 KB |
testcase_43 | AC | 16 ms
7,424 KB |
testcase_44 | AC | 19 ms
7,552 KB |
testcase_45 | AC | 17 ms
7,424 KB |
testcase_46 | AC | 17 ms
7,424 KB |
testcase_47 | AC | 17 ms
7,552 KB |
testcase_48 | AC | 18 ms
7,424 KB |
testcase_49 | AC | 18 ms
7,424 KB |
testcase_50 | AC | 17 ms
7,424 KB |
testcase_51 | AC | 17 ms
7,424 KB |
testcase_52 | AC | 19 ms
7,424 KB |
testcase_53 | AC | 17 ms
7,424 KB |
testcase_54 | AC | 16 ms
7,552 KB |
testcase_55 | AC | 17 ms
7,424 KB |
testcase_56 | AC | 17 ms
7,424 KB |
testcase_57 | AC | 17 ms
7,424 KB |
testcase_58 | AC | 16 ms
7,424 KB |
testcase_59 | AC | 17 ms
7,424 KB |
testcase_60 | AC | 16 ms
7,296 KB |
testcase_61 | AC | 17 ms
7,552 KB |
testcase_62 | AC | 17 ms
7,424 KB |
testcase_63 | AC | 17 ms
7,296 KB |
testcase_64 | AC | 30 ms
7,424 KB |
testcase_65 | AC | 17 ms
7,424 KB |
testcase_66 | AC | 16 ms
7,424 KB |
testcase_67 | AC | 17 ms
7,424 KB |
testcase_68 | AC | 17 ms
7,424 KB |
testcase_69 | AC | 17 ms
7,424 KB |
testcase_70 | AC | 43 ms
7,424 KB |
testcase_71 | AC | 17 ms
7,424 KB |
testcase_72 | AC | 17 ms
7,424 KB |
testcase_73 | AC | 17 ms
7,424 KB |
testcase_74 | AC | 16 ms
7,552 KB |
testcase_75 | AC | 17 ms
7,424 KB |
testcase_76 | AC | 19 ms
7,424 KB |
testcase_77 | AC | 17 ms
7,552 KB |
testcase_78 | AC | 17 ms
7,424 KB |
testcase_79 | AC | 17 ms
7,424 KB |
testcase_80 | AC | 19 ms
7,424 KB |
testcase_81 | AC | 28 ms
7,296 KB |
testcase_82 | AC | 17 ms
7,424 KB |
testcase_83 | AC | 17 ms
7,424 KB |
testcase_84 | AC | 28 ms
7,424 KB |
testcase_85 | AC | 17 ms
7,296 KB |
testcase_86 | AC | 30 ms
7,424 KB |
testcase_87 | AC | 32 ms
7,296 KB |
testcase_88 | AC | 17 ms
7,296 KB |
testcase_89 | AC | 17 ms
7,424 KB |
testcase_90 | AC | 39 ms
7,424 KB |
testcase_91 | AC | 17 ms
7,424 KB |
testcase_92 | AC | 17 ms
7,424 KB |
testcase_93 | AC | 17 ms
7,424 KB |
testcase_94 | AC | 18 ms
7,296 KB |
testcase_95 | AC | 17 ms
7,424 KB |
testcase_96 | AC | 16 ms
7,296 KB |
testcase_97 | AC | 17 ms
7,424 KB |
testcase_98 | AC | 17 ms
7,424 KB |
testcase_99 | AC | 17 ms
7,552 KB |
testcase_100 | WA | - |
testcase_101 | AC | 41 ms
7,552 KB |
testcase_102 | AC | 17 ms
7,296 KB |
testcase_103 | AC | 16 ms
7,296 KB |
testcase_104 | AC | 17 ms
7,424 KB |
testcase_105 | AC | 17 ms
7,424 KB |
testcase_106 | AC | 17 ms
7,424 KB |
ソースコード
from random import randint from collections import deque from math import sqrt n = input() M = min(1003, n) prime = [1]*(M+1) prime[0] = prime[1] = 0 p_num = 0 for i in xrange(2, int(sqrt(M))+1): if prime[i]: for j in xrange(i*i, M+1, i): prime[j] = 0 def fermat(k): for t in xrange(1000): a = randint(2, k-1) if pow(a, k-1, k)!=1: return 0 return 1 i = 2 while i<=40: deq = deque() deq.append(1) used = [0]*(M+1) ok = 0 while deq: v = deq.popleft() if n>M and v%i==0: ok = 1 break if v==n: print i exit(0) if v+1 <= M and v%i!=0 and not prime[v+1] and not used[v+1]: used[v+1] = 1 deq.append(v+1) if v-1 >= 1 and v%i!=1 and not prime[v-1] and not used[v-1]: used[v-1] = 1 deq.append(v-1) if v+i <= M and not prime[v+i] and not used[v+i]: used[v+i] = 1 deq.append(v+i) if v-i >= 1 and not prime[v-i] and not used[v-i]: used[v-i] = 1 deq.append(v-i) if ok: if (n%i!=1 and not fermat(n-1)) or not fermat(n-i): print i exit(0) i += 1 exit(1)