結果
| 問題 |
No.1181 Product Sum for All Subsets
|
| コンテスト | |
| ユーザー |
hashiryo
|
| 提出日時 | 2020-08-21 21:32:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,018 bytes |
| コンパイル時間 | 1,499 ms |
| コンパイル使用メモリ | 166,804 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 05:15:37 |
| 合計ジャッジ時間 | 2,319 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n) \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;
template <int mod>
struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) { return *this *= p.inverse(); }
ModInt operator-() const { return ModInt() - *this; }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b) t = a / b, swap(a -= t * b, b), swap(u -= t * v, v);
return ModInt(u);
}
ModInt pow(int64_t e) const {
ModInt ret(1);
for (ModInt b = *this; e; e >>= 1, b *= b)
if (e & 1) ret *= b;
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int modulo() { return mod; }
};
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
using Mint = ModInt<int(1e9 + 7)>;
int N;
Mint K;
cin >> N >> K;
Mint a = K * (K + 1) / Mint(2);
cout << (a + K).pow(N) - a.pow(N) << endl;
return 0;
}
hashiryo