結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー maspymaspy
提出日時 2020-08-26 00:13:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 414 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 33,104 KB
最終ジャッジ日時 2023-09-30 14:41:13
合計ジャッジ時間 6,934 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
32,220 KB
testcase_01 AC 212 ms
32,064 KB
testcase_02 AC 258 ms
32,332 KB
testcase_03 AC 258 ms
32,360 KB
testcase_04 AC 256 ms
32,536 KB
testcase_05 AC 326 ms
32,332 KB
testcase_06 AC 332 ms
32,180 KB
testcase_07 AC 326 ms
32,392 KB
testcase_08 AC 400 ms
32,424 KB
testcase_09 AC 407 ms
33,104 KB
testcase_10 AC 412 ms
33,080 KB
testcase_11 AC 409 ms
32,268 KB
testcase_12 AC 414 ms
32,452 KB
testcase_13 AC 159 ms
32,388 KB
testcase_14 AC 384 ms
32,192 KB
testcase_15 AC 407 ms
32,224 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) % n == 0:
            return d

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