結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー yuusanlondonyuusanlondon
提出日時 2020-10-09 23:04:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 835 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 844,360 KB
最終ジャッジ日時 2023-09-27 19:23:34
合計ジャッジ時間 3,627 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# Python3 program to calculate  
# discrete logarithm 
import math; 
  
def discreteLogarithm(a, b, m):  
  
    n = int(math.sqrt (m) + 1); 
  
    # Calculate a ^ n  
    an = 1; 
    for i in range(n): 
        an = (an * a) % m; 
  
    value = [0] * m; 
  
    # Store all values of a^(n*i) of LHS 
    cur = an; 
    for i in range(1, n + 1): 
        if (value[ cur ] == 0): 
            value[ cur ] = i; 
        cur = (cur * an) % m; 
      
    cur = b; 
    for i in range(n + 1): 
          
        # Calculate (a ^ j) * b and check 
        # for collision 
        if (value[cur] > 0): 
            ans = value[cur] * n - i; 
            if (ans < m): 
                return ans; 
        cur = (cur * a) % m; 
  
    return -1; 
t=int(input())
for _ in range(t):
  n=int(input())
  print(discreteLogarithm(2,1,2*n-1))
0