結果
問題 | No.1518 Simple Combinatorics |
ユーザー |
|
提出日時 | 2024-08-31 12:32:29 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,297 bytes |
コンパイル時間 | 3,585 ms |
コンパイル使用メモリ | 272,812 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-31 12:32:33 |
合計ジャッジ時間 | 4,754 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h>using i64 = long long;constexpr int P = 1e9 + 7;template <typename T>T expow(T a, T b) {T res = 1 % P;for (; b; b >>= 1) {if (b & 1) res = 1ll * res * a % P;a = 1ll * a * a % P;}return res;}template <typename T> T read() {T sum = 0, fl = 1;int ch = getchar();for (; !isdigit(ch); ch = getchar()) { if (ch == '-') fl = -1; }for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';return sum * fl;}template <typename T> void write(T x) {if (x < 0) { x = -x; putchar('-'); }if (x > 9) write(x / 10);putchar(x % 10 + '0');}/* with unlocked: only available on Linux platform */// template <typename T> T read() {// T sum = 0, fl = 1;// int ch = getchar_unlocked();// for (; !isdigit(ch); ch = getchar_unlocked()) { if (ch == '-') fl = -1; }// for (; isdigit(ch); ch = getchar_unlocked()) sum = sum * 10 + ch - '0';// return sum * fl;// }// template <typename T> void write(T x) {// if (x < 0) { x = -x; putchar_unlocked('-'); }// if (x > 9) write(x / 10);// putchar_unlocked(x % 10 + '0');// }int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int n = read<int>(), k = read<int>();i64 res = n * (expow<i64>(n, k) + P - expow<i64>(n - 1, k)) % P;write<i64>(res);return 0;}