結果
| 問題 |
No.1255 ハイレーツ・オブ・ボリビアン
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2020-10-09 23:30:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 949 bytes |
| コンパイル時間 | 2,063 ms |
| コンパイル使用メモリ | 199,424 KB |
| 最終ジャッジ日時 | 2025-01-15 05:52:45 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 WA * 12 |
ソースコード
#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;
}
沙耶花