結果

問題 No.573 a^2[i] = a[i]
ユーザー chocorusk
提出日時 2018-09-20 04:17:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 903 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 78,584 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-18 08:27:01
合計ジャッジ時間 1,909 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k/=2;
    }
    return ans;
}

ll inv(ll a){
	return powmod(a, MOD-2);
}

int main()
{
	int n;
	cin>>n;
	ll f[100001];
	f[0]=1;
	for(ll i=1; i<=n; i++){
		f[i]=f[i-1]*i%MOD;
	}
	ll invf[100001];
	invf[n]=inv(f[n]);
	for(ll i=n-1; i>=0; i--){
		invf[i]=invf[i+1]*(i+1)%MOD;
	}
	ll ans=0;
	for(ll i=1; i<=n; i++){
		ans+=f[n]*invf[i]%MOD*invf[n-i]%MOD*powmod(i, (ll)(n-i))%MOD;
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}
0