結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-10-09 21:54:13
言語 D
(dmd 2.106.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,639 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 115,892 KB
実行使用メモリ 6,756 KB
最終ジャッジ日時 2023-09-04 10:23:56
合計ジャッジ時間 9,100 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 841 ms
6,692 KB
testcase_09 AC 877 ms
6,656 KB
testcase_10 AC 834 ms
6,724 KB
testcase_11 AC 866 ms
6,756 KB
testcase_12 AC 887 ms
6,688 KB
testcase_13 AC 65 ms
6,580 KB
testcase_14 TLE -
testcase_15 AC 805 ms
6,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


Int mod(Int)(Int a, Int m) {
  if ((a %= m) < 0) a += m; return a;
}
Int gcd(Int)(Int a, Int b) { return (b != 0) ? gcd(b, a % b) : a; }
Int lcm(Int)(Int a, Int b) { return a / gcd(a, b) * b; }
Int gojo(Int)(Int a, Int b, out Int x, out Int y) {
  if (b != 0) { Int g = gojo(b, a % b, y, x); y -= (a / b) * x; return g; }
  x = 1; y = 0; return a;
}
Int modInv(Int)(Int a, Int m) { Int x, y; gojo(a, m, x, y); return mod(x, m); }
long modLogP(long a, long b, long m) {
	a = mod(a, m); b = mod(b, m);
	if (m == 1) return 0;
	long k, ak = 1;
	Tuple!(long,long)[] as;
	for (k = 0; k * k < m; ++k) {
		as ~= tuple(ak, k);
		ak = (ak * a) % m;
	}
	as.sort;
	ak = modInv(ak, m);
	for (long i = 0; i < k; ++i) {
		int pos = as.lowerBound(tuple(b, 0L));
		if (pos < as.length && as[pos][0] == b) return i * k + as[pos][1];
		b = (b * ak) % m;
	}
	return -1;
}
long modLog(long a, long b, long m) {
	a = mod(a, m); b = mod(b, m);
	long f, g, r = 1 % m;
	for (f = 0; (g = gcd(a, m)) > 1; ++f) {
		if (b % g != 0) return (r == b) ? f : -1;
		b /= g; m /= g;
		r = (r * (a / g)) % m;
	}
	long res = modLogP(a, b * modInv(r, m) % m, m);
	return (res != -1) ? (f + res) : -1;
}


void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readLong();
        const M = 2 * N - 1;
        const ans = 1 + modLogP(2, modInv!long(2, M), M);
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}
0