結果

問題 No.1049 Zero (Exhaust)
ユーザー HaarHaar
提出日時 2020-05-08 22:07:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 3,313 bytes
コンパイル時間 2,610 ms
コンパイル使用メモリ 192,820 KB
最終ジャッジ日時 2025-01-10 08:47:49
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
template <uint32_t M> class ModInt{
public:
uint64_t val;
constexpr ModInt(): val(0){}
constexpr ModInt(std::int64_t n){
if(n >= M) val = n % M;
else if(n < 0) val = n % M + M;
else val = n;
}
inline constexpr auto operator+(const ModInt &a) const {return ModInt(val + a.val);}
inline constexpr auto operator-(const ModInt &a) const {return ModInt(val - a.val);}
inline constexpr auto operator*(const ModInt &a) const {return ModInt(val * a.val);}
inline constexpr auto operator/(const ModInt &a) const {return ModInt(val * a.inv().val);}
inline constexpr auto& operator=(const ModInt &a){val = a.val; return *this;}
inline constexpr auto& operator+=(const ModInt &a){if((val += a.val) >= M) val -= M; return *this;}
inline constexpr auto& operator-=(const ModInt &a){if(val < a.val) val += M; val -= a.val; return *this;}
inline constexpr auto& operator*=(const ModInt &a){(val *= a.val) %= M; return *this;}
inline constexpr auto& operator/=(const ModInt &a){(val *= a.inv().val) %= M; return *this;}
inline constexpr bool operator==(const ModInt &a) const {return val == a.val;}
inline constexpr bool operator!=(const ModInt &a) const {return val != a.val;}
inline constexpr auto& operator++(){*this += 1; return *this;}
inline constexpr auto& operator--(){*this -= 1; return *this;}
inline constexpr auto operator++(int){auto t = *this; *this += 1; return t;}
inline constexpr auto operator--(int){auto t = *this; *this -= 1; return t;}
inline constexpr static ModInt power(int64_t n, int64_t p){
if(p < 0) return power(n, -p).inv();
int64_t ret = 1, e = n;
for(; p; (e *= e) %= M, p >>= 1) if(p & 1) (ret *= e) %= M;
return ret;
}
inline constexpr static ModInt inv(int64_t a){
int64_t b = M, u = 1, v = 0;
while(b){
int64_t t = a / b;
a -= t * b; std::swap(a,b);
u -= t * v; std::swap(u,v);
}
u %= M;
if(u < 0) u += M;
return u;
}
inline constexpr static auto frac(int64_t a, int64_t b){return ModInt(a) / ModInt(b);}
inline constexpr auto power(int64_t p) const {return power(val, p);}
inline constexpr auto inv() const {return inv(val);}
friend inline constexpr auto operator-(const ModInt &a){return ModInt(-a.val);}
friend inline constexpr auto operator+(int64_t a, const ModInt &b){return ModInt(a) + b;}
friend inline constexpr auto operator-(int64_t a, const ModInt &b){return ModInt(a) - b;}
friend inline constexpr auto operator*(int64_t a, const ModInt &b){return ModInt(a) * b;}
friend inline constexpr auto operator/(int64_t a, const ModInt &b){return ModInt(a) / b;}
friend std::istream& operator>>(std::istream &s, ModInt<M> &a){s >> a.val; return s;}
friend std::ostream& operator<<(std::ostream &s, const ModInt<M> &a){s << a.val; return s;}
template <int N>
inline static auto div(){
static auto value = inv(N);
return value;
}
};
using mint = ModInt<1000000007>;
int main(){
int64_t P, K;
while(std::cin >> P >> K){
mint ans = 1;
mint s = 0;
for(int i = 0; i < K; ++i){
auto a = ans * (1 + P) + s * (P - 1) * 2;
auto b = ans + s * (P - 1) * 2;
ans = a;
s = b;
}
std::cout << ans << "\n";
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0