結果
問題 | No.573 a^2[i] = a[i] |
ユーザー |
![]() |
提出日時 | 2018-10-02 23:20:26 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 63 ms / 2,000 ms |
コード長 | 928 bytes |
コンパイル時間 | 690 ms |
コンパイル使用メモリ | 54,740 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-10-12 10:06:57 |
合計ジャッジ時間 | 3,014 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
ソースコード
#include <iostream> using namespace std; using ll = long long; ll mod=1000000007; ll mod_pow(ll a,ll b){//a^b ll ans = 1; while(b!=0){ if(b%2==0){ b = b/2; a = (a*a)%mod; } else{ ans = (ans *a)%mod; b--; } } return ans; } ll combi(ll N_, ll C_) { const int NUM_=400001; static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1]; if (fact[0]==0) { inv[1]=fact[0]=factr[0]=1; for (int i=2;i<=NUM_;++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod; for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mod, factr[i]=factr[i-1]*inv[i]%mod; } if(C_<0 || C_>N_) return 0; return factr[C_]*fact[N_]%mod*factr[N_-C_]%mod; } int main(){ int n; cin >> n; ll ans = 0; for(int i = 1; i <= n; i++){ ans += combi(n,i) * mod_pow(i,n-i); ans %= mod; } cout << ans << endl; }