結果
| 問題 |
No.1287 えぬけー
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2020-11-13 23:06:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 4,578 bytes |
| コンパイル時間 | 2,379 ms |
| コンパイル使用メモリ | 203,752 KB |
| 最終ジャッジ日時 | 2025-01-15 23:52:34 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 TLE * 4 |
ソースコード
#include <bits/stdc++.h>
template <class T, class U, class AssociativeOp = std::multiplies<>>
constexpr T power(T a, U n, T init = 1, AssociativeOp op = AssociativeOp{}) {
static_assert(std::is_integral_v<U> and not std::is_same_v<U, bool>);
assert(n >= 0);
while (n) {
if (n & 1) init = op(init, a);
if (n >>= 1) a = op(a, a);
}
return init;
}
template <uint32_t Modulus>
class ModularInt {
using M = ModularInt;
public:
static_assert(int(Modulus) >= 1, "Modulus must be in the range [1, 2^31)");
static constexpr int modulus() { return Modulus; }
static M raw(uint32_t v) {
M res;
return res.v_ = v, res;
}
ModularInt() : v_(0) {}
ModularInt(int64_t v) : v_((v %= Modulus) < 0 ? v + Modulus : v) {}
explicit operator int() const { return v_; }
M& operator++() { return v_ = ++v_ == Modulus ? 0 : v_, *this; }
M& operator--() { return --(v_ ? v_ : v_ = Modulus), *this; }
M operator+() const { return *this; }
M operator-() const { return raw(v_ ? Modulus - v_ : 0); }
M& operator*=(M o) { return v_ = uint64_t(v_) * o.v_ % Modulus, *this; }
M& operator/=(M o) {
auto [inv, gcd] = extgcd(o.v_, Modulus);
assert(gcd == 1);
return *this *= inv;
}
M& operator+=(M o) {
return v_ = int(v_ += o.v_ - Modulus) < 0 ? v_ + Modulus : v_, *this;
}
M& operator-=(M o) {
return v_ = int(v_ -= o.v_) < 0 ? v_ + Modulus : v_, *this;
}
friend M operator++(M& a, int) { return std::exchange(a, ++M(a)); }
friend M operator--(M& a, int) { return std::exchange(a, --M(a)); }
friend M operator*(M a, M b) { return a *= b; }
friend M operator/(M a, M b) { return a /= b; }
friend M operator+(M a, M b) { return a += b; }
friend M operator-(M a, M b) { return a -= b; }
friend std::istream& operator>>(std::istream& is, M& x) {
int64_t v;
return is >> v, x = v, is;
}
friend std::ostream& operator<<(std::ostream& os, M x) { return os << x.v_; }
friend bool operator==(M a, M b) { return a.v_ == b.v_; }
friend bool operator!=(M a, M b) { return a.v_ != b.v_; }
private:
static std::array<int, 2> extgcd(int a, int b) {
std::array x{1, 0};
while (b) std::swap(x[0] -= a / b * x[1], x[1]), std::swap(a %= b, b);
return {x[0], a};
}
uint32_t v_;
};
#pragma region my_template
struct Rep {
struct I {
int i;
void operator++() { ++i; }
int operator*() const { return i; }
bool operator!=(I o) const { return i < *o; }
};
const int l, r;
Rep(int _l, int _r) : l(_l), r(_r) {}
Rep(int n) : Rep(0, n) {}
I begin() const { return {l}; }
I end() const { return {r}; }
};
struct Per {
struct I {
int i;
void operator++() { --i; }
int operator*() const { return i; }
bool operator!=(I o) const { return i > *o; }
};
const int l, r;
Per(int _l, int _r) : l(_l), r(_r) {}
Per(int n) : Per(0, n) {}
I begin() const { return {r - 1}; }
I end() const { return {l - 1}; }
};
template <class F>
struct Fix : private F {
Fix(F f) : F(f) {}
template <class... Args>
decltype(auto) operator()(Args&&... args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
template <class T = int>
T scan() {
T res;
std::cin >> res;
return res;
}
template <class T, class U = T>
bool chmin(T& a, U&& b) {
return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
return a < b ? a = std::forward<U>(b), true : false;
}
#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif
using namespace std;
#define ALL(c) begin(c), end(c)
#pragma endregion
#define rep(i, a, b) for (int i = a; i < int(b); ++i)
using ll = long long;
ll modLog(ll a, ll b, ll m) {
ll n = (ll)sqrt(m) + 1, e = 1, f = 1, j = 1;
unordered_map<ll, ll> A;
while (j <= n && (e = f = e * a % m) != b % m) A[e * b % m] = j++;
if (e == b % m) return j;
if (__gcd(m, e) == __gcd(m, b))
rep(i, 2, n + 2) if (A.count(e = e * f % m)) return n * i - A[e];
return -1;
}
using Mint7 = ModularInt<int(1e9) + 7>;
using Mint6 = ModularInt<int(1e9) + 6>;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(20);
for (int tt = scan(); tt--;) {
int x = scan(), k = scan();
Mint6 logx = modLog(5, x, int(1e9) + 7);
cout << (x ? power<Mint7>(5, int(logx / k)) : 0) << '\n';
}
}
risujiroh