結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー 沙耶花沙耶花
提出日時 2020-10-10 15:58:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,082 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 208,668 KB
実行使用メモリ 5,820 KB
最終ジャッジ日時 2023-09-27 21:30:36
合計ジャッジ時間 6,668 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 460 ms
5,492 KB
testcase_09 AC 490 ms
5,704 KB
testcase_10 AC 496 ms
5,624 KB
testcase_11 AC 491 ms
5,488 KB
testcase_12 AC 511 ms
5,492 KB
testcase_13 AC 42 ms
5,820 KB
testcase_14 AC 1,082 ms
5,548 KB
testcase_15 AC 468 ms
5,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long modlog(long long a,long long b,long long m){
	long long sq;
	{
		long long ng = 0LL,ok = m;
		while(ok-ng>1){
			long long mid = (ok+ng)/2;
			if(mid*mid>=m){
				ok = mid;
			}
			else ng = mid;
		}
		sq = ok+1;
	}
	
	unordered_map<long long,long long> mp;
	long long t = 1;
	rep(i,sq){
		if(!mp.count(t)){
			mp[t] = i;
		}
		t *= a;
		t %= m;
	}
	t = inv_mod(t,m);
	long long now = 1;
	rep(i,sq){
		long long temp = b * now;
		temp %= m;
		if(mp.count(temp)){
			return i*sq + mp[temp];
		}
		now *= t;
		now %= m;
	}
	
	return -1;
	
}

int main(){	

	int t;
	cin>>t;
	
	rep(_,t){
		long long n;
		cin>>n;
		
		long long m = 2*n-1;
		if(n==1)cout<<1<<endl;
		else cout<<modlog(2,inv_mod(2,m),m)+1<<endl;
	}
	
    return 0;
}
0