File tree Expand file tree Collapse file tree 2 files changed +20
-27
lines changed Expand file tree Collapse file tree 2 files changed +20
-27
lines changed Original file line number Diff line number Diff line change 1
- const int MOD = int ( 1e9 + 7 ) ;
1
+ const int md = 1e9 + 7 ;
2
2
3
- template <typename T>
4
- T sub (T a, T b) {
5
- return (1LL *(a-b)%MOD + MOD) % MOD;
6
- }
7
-
8
- template <typename T>
9
- T add (T a, T b) {
10
- return (1LL *(a%MOD) + 1LL *(b%MOD)) % MOD;
11
- }
12
-
13
- template <typename T>
14
- T mul (T a, T b) {
15
- return (1LL *(a%MOD) * (b%MOD)) % MOD;
16
- }
3
+ template <typename T> T sub (T a, T b) { return (1LL *(a-b)%md + md) % md; }
4
+ template <typename T> T add (T a, T b) { return (1LL *(a%md) + 1LL *(b%md)) % md; }
5
+ template <typename T> T mul (T a, T b) { return (1LL *(a%md) * (b%md)) % md; }
17
6
18
- template <typename T, typename U>
19
- T fastpow (T a, U b) {
7
+ template <typename T, typename U> T fastpow (T a, U b) {
20
8
assert (0 <= b);
21
9
T answer = static_cast <T>(1 );
22
10
while (b > 0 ) {
@@ -29,22 +17,18 @@ T fastpow(T a, U b) {
29
17
return answer;
30
18
}
31
19
32
- template <typename T>
33
- T inverse (T a) {
34
- a %= MOD;
35
- if (a < 0 ) a += MOD;
36
- T b = MOD, u = 0 , v = 1 ;
20
+ template <typename T> T inverse (T a) {
21
+ a %= md;
22
+ if (a < 0 ) a += md;
23
+ T b = md, u = 0 , v = 1 ;
37
24
while (a) {
38
25
T t = b / a;
39
26
b -= t * a; swap (a, b);
40
27
u -= t * v; swap (u, v);
41
28
}
42
29
assert (b == 1 );
43
- if (u < 0 ) u += MOD ;
30
+ if (u < 0 ) u += md ;
44
31
return u;
45
32
}
46
33
47
- template <typename T>
48
- T division (T a, T b) {
49
- return mul (a, inverse (b));
50
- }
34
+ template <typename T> T division (T a, T b) { return mul (a, inverse (b)); }
Original file line number Diff line number Diff line change
1
+ // inline int add(int a, int b, const int& mod) { return (a+b>=mod)? a+b-mod : a+b; }
2
+ // inline int sub(int a, int b, const int& mod) { return (a-b<0)? a-b+mod : a-b; }
3
+ // inline int mul(int a, int b, const int& mod) { return (1LL*a*b)%mod; }
4
+
5
+ const int md = 1e9 + 7 ;
6
+
7
+ inline int add (int a, int b) { return (a+b>=md)? a+b-md : a+b; }
8
+ inline int sub (int a, int b) { return (a-b<0 )? a-b+md : a-b; }
9
+ inline int mul (int a, int b) { return (1LL *a*b)%md; }
You can’t perform that action at this time.
0 commit comments