|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define uchar unsigned char
typedef struct long_ {
uchar l;
uchar a[100];
} long_;
long x1, x2, y1_, y2, N, M, tmp, j;
long_ s, a;
uchar b[200], c[200];
long i;
uchar gcd(uchar a,uchar b)
{
while (a != 0 && b != 0) {
if (a > b)
a %= b;
else
b %= a;
}
return (a + b);
}
void mul(long_ *a,long b)
{
uchar i, c;
long K = 0;
uchar FORLIM;
FORLIM = a->l;
for (i = 0; i <= FORLIM - 1; i++) {
c = a->a[i];
a->a[i] = (b * c + K) % 10;
K = (b * c + K) / 10;
}
while (K != 0) {
a->l++;
a->a[a->l - 1] = K % 10;
K /= 10;
}
}
void add(long_ *a,long_ *b)
{
uchar l, c, i;
uchar k = 0;
if (a->l > b->l)
l = a->l;
else
l = b->l;
for (i = 0; i <= l - 1; i++) {
c = a->a[i];
a->a[i] = (c + b->a[i] + k) % 10;
k = (c + b->a[i] + k) / 10;
}
a->l = l;
if (k != 0) {
a->l++;
a->a[a->l - 1] = k;
}
}
void cnk(uchar i1,uchar j1,uchar i2,uchar j2)
{
long h1 = 0, h2 = 0;
long i, j;
for (i = i1 - j1 + 1; i <= i1; i++) {
h1++;
b[h1-1] = i;
}
for (i = i2 - j2 + 1; i <= i2; i++) {
h1++;
b[h1-1] = i;
}
for (i = 1; i <= j1; i++) {
h2++;
c[h2-1] = i;
}
for (i = 1; i <= j2; i++) {
h2++;
c[h2-1] = i;
}
for (i = 0; i < h1; i++) {
for (j = 0; j < h2; j++) {
tmp = gcd(b[i], c[j]);
b[i] /= tmp;
c[j] /= tmp;
if (b[i] == 1) {
break;
}
}
}
for (i = 0; i < h1; i++) {
if (b[i] != 1)
mul(&a, (long)b[i]);
}
}
int main(void)
{
long FORLIM;
scanf("%ld%ld%ld%ld", &x1, &y1_, &x2, &y2);
N = abs(x2 - x1) + 1;
M = abs(y2 - y1_) + 1;
if (N < M) {
tmp = N;
N = M;
M = tmp;
}
FORLIM = N;
for (i = 0; i < FORLIM; i++) {
if (i - M >= -1 && N - i >= i - M + 2) {
memset(&a, 0, sizeof(a));
a.a[0] = 1;
a.l = 1;
cnk((int)(N - 1), (int)i, (int)(N - i - 1), (int)(i - M + 1));
add(&s, &a);
}
}
for (i = s.l; i >= 1; i--)
printf("%d", s.a[i-1]);
putchar('\n');
return 0;
}
|
|