結果

問題 No.308 素数は通れません
ユーザー 👑 kmjpkmjp
提出日時 2015-12-01 00:42:19
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 948 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 6,712 KB
実行使用メモリ 9,092 KB
最終ジャッジ日時 2023-10-12 06:08:06
合計ジャッジ時間 4,960 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,752 KB
testcase_01 AC 15 ms
8,820 KB
testcase_02 AC 15 ms
8,796 KB
testcase_03 AC 15 ms
8,980 KB
testcase_04 AC 15 ms
8,784 KB
testcase_05 AC 15 ms
8,772 KB
testcase_06 AC 15 ms
8,752 KB
testcase_07 AC 15 ms
8,888 KB
testcase_08 AC 15 ms
8,892 KB
testcase_09 AC 15 ms
8,808 KB
testcase_10 AC 15 ms
8,924 KB
testcase_11 AC 14 ms
8,916 KB
testcase_12 AC 15 ms
8,992 KB
testcase_13 AC 15 ms
8,808 KB
testcase_14 AC 15 ms
8,992 KB
testcase_15 AC 15 ms
8,744 KB
testcase_16 AC 15 ms
8,940 KB
testcase_17 AC 15 ms
8,916 KB
testcase_18 AC 15 ms
9,000 KB
testcase_19 AC 15 ms
8,744 KB
testcase_20 AC 14 ms
8,800 KB
testcase_21 AC 15 ms
8,996 KB
testcase_22 AC 15 ms
8,996 KB
testcase_23 AC 15 ms
8,812 KB
testcase_24 AC 15 ms
8,804 KB
testcase_25 AC 15 ms
8,928 KB
testcase_26 AC 14 ms
8,912 KB
testcase_27 AC 15 ms
8,924 KB
testcase_28 AC 15 ms
8,820 KB
testcase_29 AC 14 ms
8,824 KB
testcase_30 AC 15 ms
8,800 KB
testcase_31 AC 15 ms
8,784 KB
testcase_32 AC 15 ms
8,940 KB
testcase_33 AC 15 ms
8,940 KB
testcase_34 AC 15 ms
8,768 KB
testcase_35 AC 15 ms
8,796 KB
testcase_36 AC 16 ms
8,820 KB
testcase_37 AC 15 ms
8,792 KB
testcase_38 AC 15 ms
8,756 KB
testcase_39 AC 15 ms
8,988 KB
testcase_40 AC 15 ms
8,816 KB
testcase_41 AC 16 ms
8,960 KB
testcase_42 AC 15 ms
8,808 KB
testcase_43 AC 15 ms
8,824 KB
testcase_44 AC 15 ms
8,760 KB
testcase_45 AC 16 ms
8,952 KB
testcase_46 AC 15 ms
8,752 KB
testcase_47 AC 15 ms
8,904 KB
testcase_48 AC 15 ms
8,764 KB
testcase_49 AC 15 ms
8,784 KB
testcase_50 AC 15 ms
8,936 KB
testcase_51 AC 16 ms
8,984 KB
testcase_52 AC 15 ms
8,760 KB
testcase_53 AC 15 ms
8,756 KB
testcase_54 AC 15 ms
8,952 KB
testcase_55 AC 15 ms
8,952 KB
testcase_56 WA -
testcase_57 AC 16 ms
8,800 KB
testcase_58 AC 15 ms
8,916 KB
testcase_59 AC 16 ms
8,800 KB
testcase_60 AC 15 ms
8,824 KB
testcase_61 AC 15 ms
8,820 KB
testcase_62 AC 15 ms
8,752 KB
testcase_63 WA -
testcase_64 AC 16 ms
8,820 KB
testcase_65 AC 15 ms
8,816 KB
testcase_66 AC 15 ms
8,828 KB
testcase_67 AC 15 ms
8,968 KB
testcase_68 AC 16 ms
8,792 KB
testcase_69 AC 16 ms
8,932 KB
testcase_70 AC 15 ms
8,804 KB
testcase_71 AC 15 ms
8,932 KB
testcase_72 AC 15 ms
8,812 KB
testcase_73 AC 15 ms
8,804 KB
testcase_74 AC 15 ms
8,940 KB
testcase_75 AC 16 ms
9,008 KB
testcase_76 WA -
testcase_77 AC 15 ms
8,960 KB
testcase_78 AC 15 ms
8,992 KB
testcase_79 AC 15 ms
8,968 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 15 ms
8,908 KB
testcase_83 AC 16 ms
8,824 KB
testcase_84 WA -
testcase_85 AC 15 ms
8,796 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 15 ms
8,764 KB
testcase_89 AC 15 ms
8,828 KB
testcase_90 WA -
testcase_91 AC 16 ms
9,008 KB
testcase_92 AC 15 ms
8,960 KB
testcase_93 AC 15 ms
8,952 KB
testcase_94 AC 15 ms
8,828 KB
testcase_95 AC 15 ms
8,796 KB
testcase_96 WA -
testcase_97 AC 15 ms
8,940 KB
testcase_98 AC 15 ms
8,812 KB
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 AC 15 ms
8,804 KB
testcase_103 AC 16 ms
8,936 KB
testcase_104 AC 15 ms
8,792 KB
testcase_105 AC 15 ms
8,920 KB
testcase_106 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import random

N=input()

isok=[0]*105
vis=[0]*105
for i in range(2,105):
	for j in range(2,i):
		if i%j==0:
			isok[i]=1

def ok(N,M):
	q=[1]
	while len(q) > 0:
		v = q[-1]
		q.pop()
		
		for t in (v-1,v+1,v-M,v+M):
			if v%M==1 and t==v-1:
				continue
			if v%M==0 and t==v+1:
				continue
			if t<=0 or t>N:
				continue
			if isok[t] and vis[t]<M:
				vis[t]=M
				q.append(t)
	
	if vis[N]==M:
		return 1
	return 0

def isprime(v):
	d = v-1
	s = 0
	while d%2==0:
		s += 1
		d /= 2
	
	for i in range(10):
		a = random.randrange(0,v-2)+1
		r = pow(a,d,v)
		if r==1 or r==v-1:
			continue
		ng = 0
		for j in range(s):
			r = pow(r,2,v)
			if r == v-1:
				ng = 1
		if ng==1:
			return 0
	
	return 1


if N>=100:
	random.seed()
	for v in range(8,100):
		if isok[v+1]==0:
			continue
		if N%v!=1:
			print v
			break
		if isprime(N-v)==0:
			print v
			break
else:
	for M in range(2,105):
		if ok(N,M):
			print M
			break

0