結果
| 問題 | No.573 a^2[i] = a[i] | 
| コンテスト | |
| ユーザー |  bal4u | 
| 提出日時 | 2019-07-06 12:15:49 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 13 ms / 2,000 ms | 
| コード長 | 822 bytes | 
| コンパイル時間 | 224 ms | 
| コンパイル使用メモリ | 31,104 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-25 03:51:30 | 
| 合計ジャッジ時間 | 1,470 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 47 | 
ソースコード
// yukicoder: No.573 a^2[i] = a[i]
// 2019.7.6 bal4u
#include <stdio.h>
typedef long long ll;
#define M   1000000007
#define MAX 100000
int fact[MAX+2], inv[MAX+2], factinv[MAX+2];
int comb(int n, int k)
{
    return (int)((ll)fact[n] * factinv[k] % M * factinv[n-k] % M);
}
int bigPow(int a, int p)
{
	int r = 1;
	while (p) {
		if (p & 1) r = (ll)r * a % M;
		a = (ll)a * a % M;
		p >>= 1;
	}
	return r;
}
int main()
{
	int i, N, ans;
	scanf("%d", &N);
	fact[0] = 1, inv[1] = 1, factinv[0] = 1;
	for (i = 1; i <= N; i++) fact[i] = ((ll)fact[i-1]*i) % M;
	for (i = 2; i <= N; i++) inv[i] = (M + (-(M/i)*(ll)inv[M % i]) % M) % M;
	for (i = 1; i <= N; i++) factinv[i] = (ll)factinv[i-1] * inv[i] % M;
	ans = 0;
    for (i = 0; i <= N; i++) ans = (ans + (ll)comb(N, i)*bigPow(N-i, i)) % M;
    printf("%d\n", ans);
}
            
            
            
        