이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <assert.h>
#include <complex>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <limits.h>
#include <locale.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#pragma warning(disable:4996)
using namespace std;
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
int IT_MAX = 131072;
const ll MOD = 1000000007;
const int INF = 1034567891;
const ll LL_INF = 2234567890123456789ll;
const db PI = 3.141592653589793238;
const ldb ERR = 1E-10;
ll mul_inv(ll a, ll b)
{
ll b0 = b, t, q;
ll x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a > 1) {
q = a / b;
t = b, b = a % b, a = t;
t = x0, x0 = x1 - q * x0, x1 = t;
}
if (x1 < 0) x1 += b0;
return x1;
}
ll F[1000050];
ll powK[1000050];
ll C(int i, int j) {
ll rv = F[i];
rv = (rv * mul_inv(F[j], MOD)) % MOD;
rv = (rv * mul_inv(F[i - j], MOD)) % MOD;
return rv;
}
int main() {
int N, K, i;
scanf("%d %d", &N, &K);
F[0] = 1, powK[0] = 1;
for (i = 1; i <= N; i++) F[i] = (F[i - 1] * i) % MOD;
for (i = 1; i <= N; i++) powK[i] = (powK[i - 1] * K) % MOD;
ll ans = powK[N];
for (i = 1; i <= N / 2; i++) {
ll t = (C(N, i) - C(N, i - 1) + MOD) % MOD;
ans = (ans + t * powK[N - i]) % MOD;
}
printf("%lld\n", ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |