結果
問題 | No.1287 えぬけー |
ユーザー |
|
提出日時 | 2020-11-14 00:32:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,163 bytes |
コンパイル時間 | 1,970 ms |
コンパイル使用メモリ | 176,548 KB |
実行使用メモリ | 13,752 KB |
最終ジャッジ日時 | 2024-07-22 22:27:42 |
合計ジャッジ時間 | 5,605 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 1 TLE * 1 -- * 3 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;constexpr char newl = '\n';constexpr ll MOD = 1000000007;ll modpow(ll x, ll n, ll mod = MOD) {ll res = 1;while (n > 0) {if (n & 1) res = res * x % mod;x = x * x % mod;n >>= 1;}return res;}// y * y >= x を満たす最小の整数yを求めるll calcSquare(ll x) {ll ng = 0, ok = x;while (ok - ng > 1) {ll mid = (ng + ok) / 2;(mid * mid >= x ? ok : ng) = mid;}return ok;}struct custom_hash {static uint64_t splitmix64(uint64_t x) {// http://xorshift.di.unimi.it/splitmix64.cx += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;return x ^ (x >> 31);}size_t operator()(uint64_t x) const {static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x + FIXED_RANDOM);}};// g^x == y (mod p) の解xを求める(なければ-1を返す)constexpr ll p = MOD;unordered_map<ll, ll, custom_hash> baby_table;ll sq = calcSquare(MOD);ll modlog(ll g, ll y) {g %= p;y %= p;if (g == 1 && y != 1) return -1;if (y == 1) return 0;ll inv_gsq = modpow(modpow(g, p - 2, p), sq, p);for (ll i = 0; i < sq; i++) {if (baby_table.find(y) != baby_table.end()) {return i * sq + baby_table[y];}(y *= inv_gsq) %= p;}return -1;}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);constexpr ll g = 5;for (ll i = 0, b = 1; i < sq; i++) {baby_table[b] = i;(b *= g) %= p;}int t;cin >> t;for (int i = 0; i < t; i++) {ll x, K;cin >> x >> K;if (x == 0) {cout << 0 << newl;continue;}ll y = modlog(g, x);assert(y >= 0);y %= (MOD - 1);constexpr ll hoge = 500000003;ll ans = modpow(g, y * modpow(K, hoge - 2, MOD - 1) % (MOD - 1));cout << ans << newl;}return 0;}