結果

問題 No.573 a^2[i] = a[i]
ユーザー mamekin
提出日時 2017-10-06 23:15:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 2,205 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 106,520 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-11-17 01:56:59
合計ジャッジ時間 2,768 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

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

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
void mod_inverse(int n, vector<long long>& inv, int mod)
{
inv.assign(n+1, -1);
inv[1] = 1;
for(int i=2; i<=n; ++i)
inv[i] = inv[mod % i] * (mod - mod / i) % mod;
}
class FactorialCalculation
{
private:
const int mod;
vector<long long> factorial;
vector<long long> invFactorial;
public:
FactorialCalculation(int n, int mod) : mod(mod)
{
factorial.resize(n+1, 1);
invFactorial.resize(n+1, 1);
vector<long long> inv;
mod_inverse(n, inv, mod);
for(int i=1; i<=n; ++i){
factorial[i] = factorial[i-1] * i % mod;
invFactorial[i] = invFactorial[i-1] * inv[i] % mod;
}
}
long long getFactorial(int n){
return factorial[n];
}
long long getInvFactorial(int n){
return invFactorial[n];
}
long long getPermutation(int n, int r){
if(n < r)
return 0;
return factorial[n] * invFactorial[n-r] % mod;
}
long long getCombination(int n, int r){
if(n < r)
return 0;
return getPermutation(n, r) * invFactorial[r] % mod;
}
long long getHomogeneous(int n, int r){
return getCombination(n+r-1, r);
}
};
const int MOD = 1000000007;
long long power(int a, int b)
{
long long ret = 1;
long long tmp = a;
while(b > 0){
if(b & 1){
ret *= tmp;
ret %= MOD;
}
tmp *= tmp;
tmp %= MOD;
b >>= 1;
}
return ret;
}
int main()
{
int n;
cin >> n;
FactorialCalculation fc(2*n, MOD);
long long ans = 0;
for(int i=1; i<=n; ++i){
ans += fc.getCombination(n, i) * power(i, n-i);
ans %= MOD;
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0