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;
using namespace std;
int f(int x, int y)
{
return y & 1 ? (long long)f(x, y ^ 1)*x%p : y ? f((long long)x*x%p, y >> 1) : 1;
}
int px[4] = { 1,0,-1,0 };
int py[4] = { 0,1,0,-1 };
int L, R, M;
int g(int n, int x, int y, int z)
{
if (n == 0) return x*x + y*y;
int a = (long long)g(n - 1, x + px[z], y + py[z], z) * M % p;
z = z + 1 & 3;
int b = (long long)g(n - 1, x + px[z], y + py[z], z) * L % p;
z = z + 2 & 3;
int c = (long long)g(n - 1, x + px[z], y + py[z], z) * R % p;
return ((long long)a + b + c) * f(L + R + M, p - 2) % p;
}
int main()
{
int n;
scanf("%d%d%d%d", &n, &L, &M, &R);
printf("%d", g(n, 0, 0, 0));
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |