結果

問題 No.36 素数が嫌い!
ユーザー pekempeypekempey
提出日時 2015-09-25 14:01:31
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 816 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 6,700 KB
実行使用メモリ 13,548 KB
最終ジャッジ日時 2023-09-26 15:02:49
合計ジャッジ時間 13,111 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math, itertools, random, collections, time

def suspect(a, e, k, n):
	a = pow(a, e, n)
	if a == 1: return True
	for _ in xrange(k):
		if a == n - 1: return True
		a = a * a % n
	return False

def isprime(n):
	if n == 1: return False
	e = n - 1
	k = 0
	while e % 2 == 0:
		e /= 2
		k += 1
	if n < 2 ** 32:
		bases = [2, 3, 5, 7]
	else:
		bases = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
	for i in bases:
		if n != i and not suspect(i, e, k, n): return False
	return True

def gcd(a, b):
	if b == 0: return a
	return gcd(b, a % b)

def rho(n):
	if n == 1: return -1
	x, y, d = 2, 2, 1
	f = lambda x: (x * x + 1) % n
	while d == 1:
		x, y = f(x), f(f(x))
		d = gcd(abs(x - y), n)
	if d == n: return -1
	return d

n = input()
if isprime(n):
	print "NO"
elif rho(n) != -1:
	print "YES"
else:
	print "NO"
0