結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー 沙耶花沙耶花
提出日時 2020-10-09 23:30:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 949 bytes
コンパイル時間 1,952 ms
コンパイル使用メモリ 205,400 KB
実行使用メモリ 5,876 KB
最終ジャッジ日時 2023-09-27 19:52:48
合計ジャッジ時間 6,942 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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 AC 504 ms
5,592 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 49 ms
5,656 KB
testcase_14 AC 1,062 ms
5,580 KB
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 2000000001

int64_t mod_log(int64_t a, int64_t b, int64_t p) {
  int64_t g = 1;

  for(int64_t i = p; i; i /= 2) (g *= a) %= p;
  g = __gcd(g, p);

  int64_t t = 1, c = 0;
  for(; t % g; c++) {
    if(t == b){
		if(c!=0)return c;
	}
    (t *= a) %= p;
  }
  if(b % g) return -1;

  t /= g;
  b /= g;

  int64_t n = p / g, h = 0, gs = 1;

  for(; h * h < n; h++) (gs *= a) %= n;

  unordered_map< int64_t, int64_t > bs;
  for(int64_t s = 0, e = b; s < h; bs[e] = ++s) {
    (e *= a) %= n;
  }

  for(int64_t s = 0, e = t; s < n;) {
    (e *= gs) %= n;
    s += h;
    if(bs.count(e)){
		if(c+s-bs[e]!=0)return c + s - bs[e];
	}
  }
  return -1;
}
	
	
int main(){	

	int t;
	cin>>t;
	
	rep(_,t){
		long long n;
		cin>>n;
		
			int ans = mod_log(2,1,2*n-1);
			if(ans==-1)ans = 2*n-1;
			cout<<ans<<endl;
		
	}
	
    return 0;
}
0