結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,412 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 730 ms
168,444 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:
            if dic[y] != 0:
                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)
        print(ans)


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