Skip to content

Commit f000c02

Browse files
committed
Use "int64_t" instead of "long long" in lib/algebra
1 parent 8add409 commit f000c02

29 files changed

+134
-117
lines changed

aoj/ALDS1/ALDS1B/main-bingcd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <bits/stdc++.h>
22

3-
inline unsigned long long gcd(unsigned long long a, unsigned long long b) {
3+
inline uint64_t gcd(uint64_t a, uint64_t b) {
44
if (a == 0) return b;
55
if (b == 0) return a;
66

7-
unsigned long long g = 1;
7+
uint64_t g = 1;
88
while (b > 0) {
99
if ((a & 1) == 0 && (b & 1) == 0) {
1010
g <<= 1;

aoj/ALDS1/ALDS1B/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <bits/stdc++.h>
22

3-
inline unsigned long long gcd(unsigned long long a, unsigned long long b) {
3+
inline uint64_t gcd(uint64_t a, uint64_t b) {
44
while (b != 0) {
55
a %= b;
66
std::swap(a, b);

aoj/NTL/NTL1B/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
template<class T>
44
inline T binexp(
5-
const T& a,
6-
unsigned long long n,
7-
const T& id,
8-
const std::function<T(const T&, const T&)> op = std::multiplies<T>()
9-
) {
5+
T const& a,
6+
uint64_t n,
7+
T const& id,
8+
std::function<T(T const& lhs, T const& rhs)> const& op = std::multiplies<T>()
9+
)
10+
{
1011
auto ans = id;
1112
auto p = a;
1213
while (n > 0) {

aoj/NTL/NTL1C/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <bits/stdc++.h>
22

3-
inline unsigned long long gcd(unsigned long long a, unsigned long long b) {
3+
inline uint64_t gcd(uint64_t a, uint64_t b) {
44
while (b != 0) {
55
a %= b;
66
std::swap(a, b);
77
}
88
return a;
99
}
1010

11-
inline unsigned long long lcm(unsigned long long a, unsigned long long b) {
11+
inline uint64_t lcm(uint64_t const a, uint64_t const b) {
1212
if (a == 0 && b == 0) return 0;
1313
return a / gcd(a, b) * b;
1414
}

aoj/NTL/NTL1E/main-iterative.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#include <bits/stdc++.h>
22

3-
inline unsigned long long extgcd(unsigned long long a, unsigned long long b, long long &x, long long &y) {
3+
inline uint64_t extgcd(
4+
uint64_t const a,
5+
uint64_t const b,
6+
int64_t &x,
7+
int64_t &y
8+
)
9+
{
410
x = 1, y = 0;
5-
long long x1 = 0, y1 = 1;
6-
unsigned long long a1 = a, b1 = b;
11+
int64_t x1 = 0, y1 = 1;
12+
uint64_t a1 = a, b1 = b;
713
// a * x + b * y = a1
814
// a * x1 + b * y1 = b1
915
while (b1 > 0) {
10-
unsigned long long q = a1 / b1;
16+
uint64_t q = a1 / b1;
1117
std::tie(x, x1) = std::make_tuple(x1, x - q * x1);
1218
std::tie(y, y1) = std::make_tuple(y1, y - q * y1);
1319
std::tie(a1, b1) = std::make_tuple(b1, a1 - q * b1);
@@ -22,7 +28,7 @@ int main() {
2228
ios_base::sync_with_stdio(false);
2329
cin.tie(0); cout.tie(0);
2430

25-
long long a, b, x, y;
31+
int64_t a, b, x, y;
2632
cin >> a >> b;
2733
extgcd(a, b, x, y);
2834
cout << x << " " << y << endl;

aoj/NTL/NTL1E/main-recursive.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#include <bits/stdc++.h>
22

3-
inline unsigned long long extgcd(unsigned long long a, unsigned long long b, long long &x, long long &y) {
3+
inline uint64_t extgcd(
4+
uint64_t const a,
5+
uint64_t const b,
6+
int64_t &x, int64_t &y
7+
)
8+
{
49
if (b == 0) {
510
x = 1, y = 0;
611
return a;
712
}
8-
long long x1, y1;
9-
unsigned long long g = extgcd(b, a % b, x1, y1);
13+
int64_t x1, y1;
14+
uint64_t g = extgcd(b, a % b, x1, y1);
1015
x = y1;
1116
y = x1 - y1 * (a / b);
1217
return g;
@@ -19,7 +24,7 @@ int main() {
1924
ios_base::sync_with_stdio(false);
2025
cin.tie(0); cout.tie(0);
2126

22-
long long a, b, x, y;
27+
int64_t a, b, x, y;
2328
cin >> a >> b;
2429
extgcd(a, b, x, y);
2530
cout << x << " " << y << endl;

atcoder/abc110/D/main.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,24 @@
22

33
class Combination {
44
size_t N;
5-
unsigned long long MOD;
6-
std::vector<unsigned long long> factorial, inverse, factorial_inverse;
5+
uint64_t MOD;
6+
std::vector<uint64_t> factorial, inverse, factorial_inverse;
77

88
public:
99
// O(N)
1010
// MOD should be a prime number
11-
Combination(size_t N = 10000000, unsigned long long MOD = 1000000007) {
11+
Combination(
12+
size_t const N = 10000000,
13+
uint64_t const MOD = 1000000007
14+
)
15+
{
16+
build(N, MOD);
17+
}
18+
// Time: O(N)
19+
void build(size_t const N, uint64_t const MOD) {
1220
this->N = N;
1321
this->MOD = MOD;
14-
build();
15-
}
16-
17-
// nCk
18-
// O(1)
19-
unsigned long long operator()(size_t n, size_t k) {
20-
if (n < k || n >= N) throw;
21-
return factorial[n] * (factorial_inverse[k] * factorial_inverse[n - k] % MOD) % MOD;
22-
}
23-
24-
// O(1)
25-
size_t size() {
26-
return N;
27-
}
2822

29-
private:
30-
void build() {
3123
factorial.assign(N, 0);
3224
factorial_inverse.assign(N, 0);
3325
inverse.assign(N, 0);
@@ -41,11 +33,22 @@ class Combination {
4133
factorial_inverse[i] = factorial_inverse[i-1] * inverse[i] % MOD;
4234
}
4335
}
36+
// nCk
37+
// Time: O(1)
38+
uint64_t operator()(size_t const n, size_t const k) const {
39+
if (k > n) throw std::out_of_range("k");
40+
if (n >= N) throw std::out_of_range("n");
41+
return factorial[n] * (factorial_inverse[k] * factorial_inverse[n - k] % MOD) % MOD;
42+
}
43+
// Time: O(1)
44+
size_t size() const {
45+
return N;
46+
}
4447
};
4548

46-
inline std::vector<unsigned long long> prime_factorization(unsigned long long M) {
47-
std::vector<unsigned long long> factors;
48-
for (unsigned long long i = 2; i * i <= M; ++i) {
49+
inline std::vector<uint64_t> prime_factorization(uint64_t M) {
50+
std::vector<uint64_t> factors;
51+
for (uint64_t i = 2; i * i <= M; ++i) {
4952
while (M % i == 0) {
5053
factors.push_back(i);
5154
M /= i;

lib/cpalgo/algebra/binexp.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <functional>
45

56

@@ -17,7 +18,7 @@
1718
template<class T>
1819
inline T binexp(
1920
T const& a,
20-
unsigned long long n,
21+
uint64_t n,
2122
T const& id,
2223
std::function<T(T const& lhs, T const& rhs)> const& op = std::multiplies<T>()
2324
)

lib/cpalgo/algebra/bingcd.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <utility>
45

56

@@ -17,11 +18,11 @@
1718
// Verified:
1819
// - https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/1/ALDS1_1_B
1920
//
20-
inline unsigned long long gcd(unsigned long long a, unsigned long long b) {
21+
inline uint64_t gcd(uint64_t a, uint64_t b) {
2122
if (a == 0) return b;
2223
if (b == 0) return a;
2324

24-
unsigned long long g = 1;
25+
uint64_t g = 1;
2526
while (b > 0) {
2627
if ((a & 1) == 0 && (b & 1) == 0) {
2728
g <<= 1;

lib/cpalgo/algebra/combination_basic.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <stdexcept>
45
#include <vector>
56

@@ -20,22 +21,21 @@
2021
//
2122
class Combination {
2223
size_t N;
23-
unsigned long long MOD;
24-
std::vector<unsigned long long> factorial, inverse, factorial_inverse;
24+
uint64_t MOD;
25+
std::vector<uint64_t> factorial, inverse, factorial_inverse;
2526

2627
public:
2728
// O(N)
2829
// MOD should be a prime number
2930
Combination(
3031
size_t const N = 10000000,
31-
unsigned long long const MOD = 1000000007
32+
uint64_t const MOD = 1000000007
3233
)
3334
{
3435
build(N, MOD);
3536
}
36-
3737
// Time: O(N)
38-
void build(size_t const N, unsigned long long const MOD) {
38+
void build(size_t const N, uint64_t const MOD) {
3939
this->N = N;
4040
this->MOD = MOD;
4141

@@ -52,15 +52,13 @@ class Combination {
5252
factorial_inverse[i] = factorial_inverse[i-1] * inverse[i] % MOD;
5353
}
5454
}
55-
5655
// nCk
5756
// Time: O(1)
58-
unsigned long long operator()(size_t const n, size_t const k) const {
57+
uint64_t operator()(size_t const n, size_t const k) const {
5958
if (k > n) throw std::out_of_range("k");
6059
if (n >= N) throw std::out_of_range("n");
6160
return factorial[n] * (factorial_inverse[k] * factorial_inverse[n - k] % MOD) % MOD;
6261
}
63-
6462
// Time: O(1)
6563
size_t size() const {
6664
return N;

lib/cpalgo/algebra/extgcd_iterative.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <tuple>
45

56

@@ -12,22 +13,21 @@
1213
//
1314
// Verified:
1415
// - https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E
15-
// - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1045
1616
//
17-
inline unsigned long long extgcd(
18-
unsigned long long const a,
19-
unsigned long long const b,
20-
long long &x,
21-
long long &y
17+
inline uint64_t extgcd(
18+
uint64_t const a,
19+
uint64_t const b,
20+
int64_t &x,
21+
int64_t &y
2222
)
2323
{
2424
x = 1, y = 0;
25-
long long x1 = 0, y1 = 1;
26-
unsigned long long a1 = a, b1 = b;
25+
int64_t x1 = 0, y1 = 1;
26+
uint64_t a1 = a, b1 = b;
2727
// a * x + b * y = a1
2828
// a * x1 + b * y1 = b1
2929
while (b1 > 0) {
30-
unsigned long long q = a1 / b1;
30+
uint64_t q = a1 / b1;
3131
std::tie(x, x1) = std::make_tuple(x1, x - q * x1);
3232
std::tie(y, y1) = std::make_tuple(y1, y - q * y1);
3333
std::tie(a1, b1) = std::make_tuple(b1, a1 - q * b1);

lib/cpalgo/algebra/extgcd_recursive.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34

45
// Extended Euclidean Algorithm (Recursive)
56
// Find x and y for given a and b
@@ -20,20 +21,19 @@
2021
//
2122
// Verified:
2223
// - https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E
23-
// - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1045
2424
//
25-
inline unsigned long long extgcd(
26-
unsigned long long const a,
27-
unsigned long long const b,
28-
long long &x, long long &y
25+
inline uint64_t extgcd(
26+
uint64_t const a,
27+
uint64_t const b,
28+
int64_t &x, int64_t &y
2929
)
3030
{
3131
if (b == 0) {
3232
x = 1, y = 0;
3333
return a;
3434
}
35-
long long x1, y1;
36-
unsigned long long g = extgcd(b, a % b, x1, y1);
35+
int64_t x1, y1;
36+
uint64_t g = extgcd(b, a % b, x1, y1);
3737
x = y1;
3838
y = x1 - y1 * (a / b);
3939
return g;

lib/cpalgo/algebra/gcd.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <utility>
45

56

@@ -15,7 +16,7 @@
1516
// - https://www.codechef.com/problems/FLOW016
1617
// - https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/1/ALDS1_1_B
1718
//
18-
inline unsigned long long gcd(unsigned long long a, unsigned long long b) {
19+
inline uint64_t gcd(uint64_t a, uint64_t b) {
1920
while (b != 0) {
2021
a %= b;
2122
std::swap(a, b);

lib/cpalgo/algebra/lcm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// - https://www.codechef.com/problems/FLOW016
1515
// - https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_C
1616
//
17-
inline unsigned long long lcm(unsigned long long const a, unsigned long long const b) {
17+
inline uint64_t lcm(uint64_t const a, uint64_t const b) {
1818
if (a == 0 && b == 0) return 0;
1919
return a / gcd(a, b) * b;
2020
}

lib/cpalgo/algebra/prime_factorization_basic.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <vector>
45

56

@@ -14,9 +15,9 @@
1415
// - https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_A
1516
// - https://atcoder.jp/contests/abc110/tasks/abc110_d
1617
//
17-
inline std::vector<unsigned long long> prime_factorization(unsigned long long M) {
18-
std::vector<unsigned long long> factors;
19-
for (unsigned long long i = 2; i * i <= M; ++i) {
18+
inline std::vector<uint64_t> prime_factorization(uint64_t M) {
19+
std::vector<uint64_t> factors;
20+
for (uint64_t i = 2; i * i <= M; ++i) {
2021
while (M % i == 0) {
2122
factors.push_back(i);
2223
M /= i;

0 commit comments

Comments
 (0)