結果
問題 | No.1518 Simple Combinatorics |
ユーザー |
![]() |
提出日時 | 2023-06-13 22:26:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 655 bytes |
コンパイル時間 | 788 ms |
コンパイル使用メモリ | 101,328 KB |
最終ジャッジ日時 | 2025-02-14 02:27:49 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <iostream> #include <vector> #include <cmath> #include <map> #include <set> #include <iomanip> #include <queue> #include <algorithm> #include <numeric> #include <deque> using namespace std; using ll = long long; const ll modc = 1e9+7; ll mod_exp(ll b, ll e, ll m=modc){ if (e > 0 && b == 0) return 0; ll ans = 1; b %= m; while (e > 0){ if ((e & 1LL)) ans = (ans * b) % m; e = e >> 1LL; b = (b*b) % m; } return ans; } int main(){ ll N, K, ans; cin >> N >> K; ans = (modc + mod_exp(N, K) - mod_exp(N-1, K)) % modc; ans *= N; cout << ans % modc << endl; return 0; }