This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
const int p = 1000000007;
int pw(int x, int y)
{
return y & 1 ? (long long)pw(x, y ^ 1)*x%p : y ? pw((long long)x*x%p, y >> 1) : 1;
}
int fac[2000002];
int calc(int i, int j)
{
if (i < j) return 0;
if (i + j & 1) return 0;
int r = j + 1;
if (i & 1)
{
r = (long long)r * fac[i] % p;
r = (long long)r * pw(fac[(i + j) / 2 + 1], p - 2) % p;
r = (long long)r * pw(fac[(i - j) / 2], p - 2) % p;
}
else
{
r = (long long)r * fac[i] % p;
r = (long long)r * pw(fac[(i + j) / 2 + 1], p - 2) % p;
r = (long long)r * pw(fac[(i - j) / 2], p - 2) % p;
}
return r;
}
int main()
{
int i, n, m, r = 0;
fac[0] = 1;
for (i = 1; i <= 2000000; i++) fac[i] = (long long)fac[i - 1] * i % p;
scanf("%d%d", &n, &m);
for (i = 0; i <= n; i++) r = (r + (long long)calc(n, i)*pw(m, n + i >> 1)) % p;
printf("%d", r);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |