結果
問題 | No.2191 一元二次式 mod 奇素数 |
ユーザー | MasKoaTS |
提出日時 | 2022-11-17 12:40:55 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,839 bytes |
コンパイル時間 | 155 ms |
コンパイル使用メモリ | 81,836 KB |
実行使用メモリ | 86,012 KB |
最終ジャッジ日時 | 2023-10-19 05:02:52 |
合計ジャッジ時間 | 5,847 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
85,816 KB |
testcase_01 | AC | 141 ms
85,812 KB |
testcase_02 | AC | 137 ms
85,812 KB |
testcase_03 | AC | 140 ms
85,812 KB |
testcase_04 | AC | 139 ms
85,812 KB |
testcase_05 | AC | 140 ms
85,808 KB |
testcase_06 | AC | 139 ms
85,812 KB |
testcase_07 | AC | 140 ms
85,816 KB |
testcase_08 | AC | 140 ms
85,812 KB |
testcase_09 | WA | - |
testcase_10 | AC | 144 ms
85,812 KB |
testcase_11 | AC | 143 ms
85,812 KB |
testcase_12 | WA | - |
testcase_13 | AC | 135 ms
85,812 KB |
testcase_14 | AC | 140 ms
85,816 KB |
testcase_15 | AC | 137 ms
85,816 KB |
testcase_16 | WA | - |
testcase_17 | AC | 140 ms
85,816 KB |
testcase_18 | AC | 140 ms
85,816 KB |
testcase_19 | WA | - |
testcase_20 | AC | 141 ms
85,816 KB |
testcase_21 | AC | 138 ms
85,816 KB |
testcase_22 | AC | 140 ms
85,812 KB |
testcase_23 | WA | - |
testcase_24 | AC | 143 ms
85,816 KB |
testcase_25 | AC | 139 ms
85,808 KB |
testcase_26 | WA | - |
ソースコード
import itertools as iter import collections as coll import heapq as hq import bisect as bis from decimal import Decimal as dec from functools import cmp_to_key import math import sys #import pypyjit #pypyjit.set_param('max_unroll_recursion=-1') sys.setrecursionlimit(10 ** 6) inp = sys.stdin.readline input = lambda : inp().rstrip() getN = lambda : int(inp()) getNs = lambda : map(int, inp().split()) getList = lambda :list(map(int, inp().split())) getStrs = lambda n : [input() for _ in [0] * n] def yexit(): print("Yes"); exit(0) def nexit(): print("No"); exit(0) pi = 3.141592653589793 mod = 1000000007 MOD = 998244353 INF = 4611686018427387903 dx = [1, 0, -1, 0]; dy = [0, 1, 0, -1] #di = coll.defaultdict(int) # Tonelli-Shanks's Algorithm import random class TonelliShanks: def __init__(self, a, p): self.a = a self.p = p self.x = self.tonelli_shanks() def get_inv(self, _a, _p): return pow(_a, _p - 2, _p) def euler_criterion(self, _a, _p): return (pow(_a, (_p - 1) >> 1, _p) == 1) # x^2 \equiv a (mod p) -> x def tonelli_shanks(self) : self.a %= self.p if(self.a == 0): return 0 if(self.p == 2): return self.a if not(self.euler_criterion(self.a, self.p)): return -1 b = 1 while(self.euler_criterion(b, self.p)): b = random.randint(1, self.p - 1) q = self.p - 1 r = 0 while not(q & 1): r += 1 q >>= 1 x = pow(self.a, (q + 1) >> 1, self.p) b = pow(b, q, self.p) s = 2 while(pow(x, 2, self.p) != self.a): e = self.get_inv(self.a, self.p) * pow(x, 2, self.p) % self.p if(pow(e, 1 << (r - s), p) != 1): x *= b x %= self.p b = pow(b, 2, self.p) % self.p s += 1 return x """ Main Code """ p = getN() K = (p - 1) >> 1 a = p - abs(-4 * K * K - 16 * K + 1) % p x = TonelliShanks(a, p).x if(x == -1 or (x & 1) == 0): print("NO") else: print("YES")