結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー tamatotamato
提出日時 2020-10-09 23:07:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 859 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 87,344 KB
実行使用メモリ 168,256 KB
最終ジャッジ日時 2023-09-27 19:31:21
合計ジャッジ時間 4,886 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,660 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 564 ms
168,256 KB
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    # x**k == y % mod
    # O(mod**0.5)
    def DiscreteLog(x, y, mod):
        m = int(mod ** 0.5) + 1
        dic = {1: 0}

        # baby-step
        xi = 1
        for i in range(1, m + 1):
            xi = (xi * x) % mod
            dic[xi] = i
        if y in dic:
            return dic[y]

        # giant-step
        r = pow(xi, mod - 2, mod)
        for a in range(1, m + 1):
            y = (y * r) % mod
            if y in dic:
                return a * m + dic[y]

        return -1

    for _ in range(int(input())):
        N = int(input())
        if N == 1:
            print(1)
            continue
        ans = DiscreteLog(2, 1, 2*N-1)
        if ans == 0:
            ans = 2 * N - 2
        print(ans)


if __name__ == '__main__':
    main()
0