結果
| 問題 |
No.1287 えぬけー
|
| コンテスト | |
| ユーザー |
fastmath
|
| 提出日時 | 2020-11-13 23:46:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 75 ms / 2,000 ms |
| コード長 | 2,591 bytes |
| コンパイル時間 | 1,724 ms |
| コンパイル使用メモリ | 194,812 KB |
| 最終ジャッジ日時 | 2025-01-16 00:09:57 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 5 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
const int MOD = 1e9+7;
//need define int long long
int mod(int n) {
n %= MOD;
if (n < 0) return n + MOD;
else return n;
}
int fp(int a, int p) {
int ans = 1, c = a;
for (int i = 0; (1ll << i) <= p; ++i) {
if ((p >> i) & 1) ans = mod(ans * c);
c = mod(c * c);
}
return ans;
}
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }
struct M {
ll x;
M (int x_) {
x = mod(x_);
}
M () {
x = 0;
}
M operator + (M y) {
int ans = x + y.x;
if (ans >= MOD)
ans -= MOD;
return M(ans);
}
M operator - (M y) {
int ans = x - y.x;
if (ans < 0)
ans += MOD;
return M(ans);
}
M operator * (M y) {
return M(x * y.x % MOD);
}
M operator / (M y) {
return M(x * fp(y.x, MOD - 2) % MOD);
}
M operator + (int y) {
return (*this) + M(y);
}
M operator - (int y) {
return (*this) - M(y);
}
M operator * (int y) {
return (*this) * M(y);
}
M operator / (int y) {
return (*this) / M(y);
}
M operator ^ (int p) {
return M(fp(x, p));
}
void operator += (M y) {
*this = *this + y;
}
void operator -= (M y) {
*this = *this - y;
}
void operator *= (M y) {
*this = *this * y;
}
void operator /= (M y) {
*this = *this / y;
}
void operator += (int y) {
*this = *this + y;
}
void operator -= (int y) {
*this = *this - y;
}
void operator *= (int y) {
*this = *this * y;
}
void operator /= (int y) {
*this = *this / y;
}
void operator ^= (int p) {
*this = *this ^ p;
}
};
ll inv_mod( ll a, ll m )
{
ll b, x, u, q, abs_m, tmp;
abs_m = ( m < 0 ) ? -m : m;
b = m; x = 1ll; u = 0ll;
while ( b > 0 ) {
q = a / b;
tmp = u; u = x - q * u; x = tmp;
tmp = b; b = a - q * b; a = tmp;
}
return ( x < 0 ) ? abs_m + x : x;
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout.setf(ios::fixed); cout.precision(20);
#endif
int t;
cin >> t;
while (t--) {
int x, k;
cin >> x >> k;
k = inv_mod(k, MOD-1);
//debug(k);
cout << (M(x) ^ k).x << endl;
}
}
fastmath