-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolley.c
102 lines (88 loc) · 1.55 KB
/
volley.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int powers(long long base, long long n,long long mod)
{
if(n==0)
return 1;
if(n==1)
return base;
long long halfn = powers(base, n/2, mod);
if(n%2==0)
return ( halfn * halfn ) % mod;
else
return ( ( ( halfn * halfn ) % mod ) * base ) % mod;
}
int multi_inverse(int n, int mod)
{
return powers(n,mod-2,mod);
}
long long factorial(int n, int mod)
{
long long temp=1;
if (n==0)
{
return 1;
}
if (n ==1)
{
return 1;
}
else
{
return (n*factorial(n-1, mod))%mod;
}
}
int main()
{
long long total = 1, numerator = 1, denominator = 1, mod = 1000000007;
int a, b, i;
scanf("%d", &a);
scanf("%d", &b);
if (a<25 && b<25)
{
printf("0");
}
else if ((a > 25 || b > 25) && (abs(a - b) != 2))
{
printf("0");
}
else if ((a==24 || b==24)&&(abs(a - b) != 2))
{
printf("0");
}
else if (a==b)
{
printf("0");
}
else if(a <= 25 && b <= 25)
{
if (b > a)
{
int temp = b;
b = a;
a = temp;
}
numerator = factorial(a+b-1, mod);
denominator = (factorial(b, mod)*factorial(a-1, mod))%mod;
total = (numerator * multi_inverse(denominator, mod)) % mod;
printf("%lld", total);
}
else
{
numerator = factorial(48, mod);
denominator = (factorial(24, mod)*factorial(24, mod))%mod;
total = (numerator * multi_inverse(denominator, mod)) % mod;
if (b < a)
{
int temp = b;
b = a;
a = temp;
}
a = a-24;
total = (total * powers(2, a, mod))%mod;
printf("%lld", total);
}
return 0;
}