結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-23 14:04:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 499 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 14,536 KB
最終ジャッジ日時 2023-10-22 08:13:23
合計ジャッジ時間 8,579 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,236 KB
testcase_01 AC 30 ms
10,240 KB
testcase_02 AC 29 ms
10,240 KB
testcase_03 AC 29 ms
10,240 KB
testcase_04 AC 30 ms
10,240 KB
testcase_05 AC 33 ms
10,260 KB
testcase_06 AC 33 ms
10,260 KB
testcase_07 AC 33 ms
10,260 KB
testcase_08 AC 683 ms
14,476 KB
testcase_09 AC 758 ms
14,416 KB
testcase_10 AC 686 ms
14,496 KB
testcase_11 AC 735 ms
14,416 KB
testcase_12 AC 730 ms
14,416 KB
testcase_13 AC 93 ms
14,496 KB
testcase_14 TLE -
testcase_15 AC 643 ms
14,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main2(n):
  if n==1:return 1
  # 2^i==1 mod 2*n-1 となるiを返す
  mod=2*n-1
  d={0:1}
  now=2
  c=int(n**0.5)
  for i in range(c+3):
    if now==1:
      return i+1
    d[now]=i+1
    now=now*2%mod
  inv2=pow(2,-1,mod)
  gs=pow(inv2,c,mod)
  now=gs
  cnt=1
  while True:
    if now in d:
      # 2^(-c*cnt)=2^d[now]
      # 1=2^(c*cnt+d[now])
      return d[now]+c*cnt
    now=now*gs%mod
    cnt+=1

t=int(input())
cases=[int(input()) for _ in range(t)]
for n in cases:
  print(main2(n))
0