結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー maspymaspy
提出日時 2020-08-22 03:15:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,027 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 33,004 KB
最終ジャッジ日時 2023-09-10 14:18:53
合計ジャッジ時間 9,191 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
31,940 KB
testcase_01 AC 206 ms
32,144 KB
testcase_02 AC 254 ms
32,436 KB
testcase_03 AC 253 ms
32,072 KB
testcase_04 AC 256 ms
32,384 KB
testcase_05 AC 332 ms
32,188 KB
testcase_06 AC 333 ms
32,132 KB
testcase_07 AC 320 ms
32,296 KB
testcase_08 AC 396 ms
32,348 KB
testcase_09 AC 402 ms
33,004 KB
testcase_10 AC 401 ms
32,944 KB
testcase_11 AC 440 ms
32,340 KB
testcase_12 AC 399 ms
32,168 KB
testcase_13 WA -
testcase_14 AC 376 ms
32,128 KB
testcase_15 AC 402 ms
32,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

T, *Ns = map(int, read().split())

def prime_table(N):
    is_prime = np.zeros(N, np.int64)
    is_prime[2:3] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p >= N:
            break
        if is_prime[p]:
            is_prime[p * p::p + p] = 0
    return is_prime, np.where(is_prime)[0]

is_prime, primes = prime_table(10**5)

def euler_phi(N):
    pf = primes[N % primes == 0]
    phi = N
    for p in pf:
        phi -= phi // p
        while N % p == 0:
            N //= p
    if N > 1:
        phi -= phi // N
    return phi

def solve(n):
    n = 2 * n - 1
    # 2^k = 1 mod n となる最小の k >= 1 を求める
    phi_n = euler_phi(n)
    div = np.arange(1, 10**5 + 1)
    div = div[phi_n % div == 0]
    div = np.union1d(div, phi_n // div)
    for d in div.tolist():
        if pow(2, d, n) == 1:
            return d

for n in Ns:
    print(solve(n))
0