Skip to content

Commit 927c3bf

Browse files
committed
Convert indentation to spaces
1 parent 6adb9c9 commit 927c3bf

File tree

1 file changed

+107
-107
lines changed

1 file changed

+107
-107
lines changed

math/math.cpp

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ const int N = 100100;
1616
*/
1717
template<class T>
1818
T gcd(T a, T b) {
19-
while (b) {
20-
int tmp = a % b;
21-
a = b;
22-
b = tmp;
23-
}
24-
return a;
19+
while (b) {
20+
int tmp = a % b;
21+
a = b;
22+
b = tmp;
23+
}
24+
return a;
2525
}
2626

2727
// =====================================================================================
@@ -36,7 +36,7 @@ T gcd(T a, T b) {
3636
*/
3737
template<class T>
3838
T lcm(T a, T b) {
39-
return a / gcd(a, b) * b;
39+
return a / gcd(a, b) * b;
4040
}
4141

4242
// =====================================================================================
@@ -52,16 +52,16 @@ T lcm(T a, T b) {
5252
*/
5353
template<class T>
5454
pair<T, T> extendedEuclid(T a, T b) {
55-
if (b == 0) {
56-
return {1, 0};
57-
}
55+
if (b == 0) {
56+
return {1, 0};
57+
}
5858

59-
pair<T, T> p = extendedEuclid(b, a % b);
59+
pair<T, T> p = extendedEuclid(b, a % b);
6060

61-
T s = p.first;
62-
T t = p.second;
61+
T s = p.first;
62+
T t = p.second;
6363

64-
return {t, s - t * (a / b)};
64+
return {t, s - t * (a / b)};
6565
}
6666

6767
// =====================================================================================
@@ -80,16 +80,16 @@ pair<T, T> extendedEuclid(T a, T b) {
8080
*/
8181
template<class T>
8282
T power(T base, T exp, T mod) {
83-
T ans = 1;
84-
base %= mod;
83+
T ans = 1;
84+
base %= mod;
8585

86-
while (exp > 0) {
87-
if (exp & 1) ans = (ans * base) % mod;
88-
exp >>= 1;
89-
base = (base * base) % mod;
90-
}
86+
while (exp > 0) {
87+
if (exp & 1) ans = (ans * base) % mod;
88+
exp >>= 1;
89+
base = (base * base) % mod;
90+
}
9191

92-
return ans;
92+
return ans;
9393
}
9494

9595
// =====================================================================================
@@ -109,7 +109,7 @@ T power(T base, T exp, T mod) {
109109
*/
110110
template<class T>
111111
T modInverse(T a, T m) {
112-
return power(a, m - 2, m);
112+
return power(a, m - 2, m);
113113
}
114114

115115
// =====================================================================================
@@ -125,13 +125,13 @@ T modInverse(T a, T m) {
125125
* @return "n" choose "r".
126126
*/
127127
int nCr(int n, int r) {
128-
if (n < r)
129-
return 0;
128+
if (n < r)
129+
return 0;
130130

131-
if (r == 0)
132-
return 1;
131+
if (r == 0)
132+
return 1;
133133

134-
return n * nCr(n - 1, r - 1) / r;
134+
return n * nCr(n - 1, r - 1) / r;
135135
}
136136

137137
// =====================================================================================
@@ -149,11 +149,11 @@ int fact[N];
149149
* @param mod the modulus.
150150
*/
151151
void init(int n, int mod) {
152-
fact[0] = 1;
152+
fact[0] = 1;
153153

154-
for (int i = 1; i <= n; ++i) {
155-
fact[i] = (fact[i - 1] * 1LL * i) % mod;
156-
}
154+
for (int i = 1; i <= n; ++i) {
155+
fact[i] = (fact[i - 1] * 1LL * i) % mod;
156+
}
157157
}
158158

159159
/**
@@ -168,7 +168,7 @@ void init(int n, int mod) {
168168
* @return "n" choose "r".
169169
*/
170170
int nCr(int n, int r, int mod) {
171-
return (fact[n] * modInverse(fact[r] * 1LL * fact[n - r], mod + 0LL)) % mod;
171+
return (fact[n] * modInverse(fact[r] * 1LL * fact[n - r], mod + 0LL)) % mod;
172172
}
173173

174174
// =====================================================================================
@@ -186,9 +186,9 @@ int comb[N][N];
186186
* @param mod the modulus.
187187
*/
188188
void buildPT(int n, int mod) {
189-
for (int i = comb[0][0] = 1; i <= n; ++i)
190-
for (int j = comb[i][0] = 1; j <= i; ++j)
191-
comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod;
189+
for (int i = comb[0][0] = 1; i <= n; ++i)
190+
for (int j = comb[i][0] = 1; j <= i; ++j)
191+
comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod;
192192
}
193193

194194
// =====================================================================================
@@ -204,14 +204,14 @@ void buildPT(int n, int mod) {
204204
*/
205205
template<class T>
206206
bool isPrime(T n) {
207-
if (n < 2)
208-
return 0;
209-
if (n % 2 == 0)
210-
return (n == 2);
211-
for (int i = 3; i * i <= n; i += 2)
212-
if (n % i == 0)
213-
return 0;
214-
return 1;
207+
if (n < 2)
208+
return 0;
209+
if (n % 2 == 0)
210+
return (n == 2);
211+
for (int i = 3; i * i <= n; i += 2)
212+
if (n % i == 0)
213+
return 0;
214+
return 1;
215215
}
216216

217217
// =====================================================================================
@@ -227,23 +227,23 @@ bool isPrime(T n) {
227227
*/
228228
template<class T>
229229
bool millerRabin(T k, T q) {
230-
T n = (1LL << k) * q + 1;
231-
T a = 2 + rand() % (n - 2);
232-
T x = power(a, q, n);
230+
T n = (1LL << k) * q + 1;
231+
T a = 2 + rand() % (n - 2);
232+
T x = power(a, q, n);
233233

234-
if (x == 1) {
235-
return true;
236-
}
234+
if (x == 1) {
235+
return true;
236+
}
237237

238-
while (k--) {
239-
if (x == n - 1) {
240-
return true;
241-
}
238+
while (k--) {
239+
if (x == n - 1) {
240+
return true;
241+
}
242242

243-
x = (x * x) % n;
244-
}
243+
x = (x * x) % n;
244+
}
245245

246-
return false;
246+
return false;
247247
}
248248

249249
/**
@@ -259,30 +259,30 @@ bool millerRabin(T k, T q) {
259259
*/
260260
template<class T>
261261
bool isPrimeMillerRabin(T n, int t = 10) {
262-
if (n == 2) {
263-
return 1;
264-
}
265-
266-
if (n < 2 || n % 2 == 0) {
267-
return 0;
268-
}
269-
270-
// Compute coefficients k, q such that "n - 1 = power(2, k) * q"
271-
T k = 0;
272-
T q = n - 1;
273-
while ((q & 1) == 0) {
274-
k++;
275-
q >>= 1;
276-
}
277-
278-
// Apply probabilistic prime check for "t" times
279-
while (t--) {
280-
if (!millerRabin(k, q)) {
281-
return false;
282-
}
283-
}
284-
285-
return true;
262+
if (n == 2) {
263+
return 1;
264+
}
265+
266+
if (n < 2 || n % 2 == 0) {
267+
return 0;
268+
}
269+
270+
// Compute coefficients k, q such that "n - 1 = power(2, k) * q"
271+
T k = 0;
272+
T q = n - 1;
273+
while ((q & 1) == 0) {
274+
k++;
275+
q >>= 1;
276+
}
277+
278+
// Apply probabilistic prime check for "t" times
279+
while (t--) {
280+
if (!millerRabin(k, q)) {
281+
return false;
282+
}
283+
}
284+
285+
return true;
286286
}
287287

288288
// =====================================================================================
@@ -298,16 +298,16 @@ bool prime[N];
298298
* Complexity: O(n.log(log(n)))
299299
*/
300300
void generatePrimes(int n) {
301-
memset(prime, true, sizeof(prime));
302-
prime[0] = prime[1] = false;
301+
memset(prime, true, sizeof(prime));
302+
prime[0] = prime[1] = false;
303303

304-
for (int i = 2; i * i <= n; ++i) {
305-
if (!prime[i]) continue;
304+
for (int i = 2; i * i <= n; ++i) {
305+
if (!prime[i]) continue;
306306

307-
for (int j = i * i; j <= n; j += i) {
308-
prime[j] = false;
309-
}
310-
}
307+
for (int j = i * i; j <= n; j += i) {
308+
prime[j] = false;
309+
}
310+
}
311311
}
312312

313313
// =====================================================================================
@@ -322,13 +322,13 @@ vector<int> primeDivs[N];
322322
* Complexity: O(n.log(log(n)))
323323
*/
324324
void generatePrimeDivisors(int n) {
325-
for (int i = 2; i <= n; ++i) {
326-
if (primeDivs[i].size()) continue;
325+
for (int i = 2; i <= n; ++i) {
326+
if (primeDivs[i].size()) continue;
327327

328-
for (int j = i; j <= n; j += i) {
329-
primeDivs[j].push_back(i);
330-
}
331-
}
328+
for (int j = i; j <= n; j += i) {
329+
primeDivs[j].push_back(i);
330+
}
331+
}
332332
}
333333

334334
// =====================================================================================
@@ -344,15 +344,15 @@ void generatePrimeDivisors(int n) {
344344
*/
345345
template<class T>
346346
vector<T> getDivisors(T n) {
347-
vector<T> divs;
348-
for (T i = 1; i * i <= n; ++i) {
349-
if (n % i != 0) continue;
350-
divs.push_back(i);
351-
if (i * i == n) continue;
352-
divs.push_back(n / i);
353-
}
354-
sort(divs.begin(), divs.end());
355-
return divs;
347+
vector<T> divs;
348+
for (T i = 1; i * i <= n; ++i) {
349+
if (n % i != 0) continue;
350+
divs.push_back(i);
351+
if (i * i == n) continue;
352+
divs.push_back(n / i);
353+
}
354+
sort(divs.begin(), divs.end());
355+
return divs;
356356
}
357357

358358
// =====================================================================================
@@ -367,9 +367,9 @@ vector<int> divs[N];
367367
* Complexity: O(n.log(n))
368368
*/
369369
void generateDivisors(int n) {
370-
for (int i = 1; i <= n; ++i)
371-
for (int j = i; j <= n; j += i)
372-
divs[j].push_back(i);
370+
for (int i = 1; i <= n; ++i)
371+
for (int j = i; j <= n; j += i)
372+
divs[j].push_back(i);
373373
}
374374

375375
// =====================================================================================

0 commit comments

Comments
 (0)