-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigint.h
140 lines (119 loc) · 5.49 KB
/
bigint.h
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
#include <iostream>
#include <string>
class BigInt
{
private:
std::string value = "0";
bool sign = false;
public:
BigInt()=default;
BigInt(const std::string&);
BigInt(std::string&&);
BigInt(const char*);
BigInt& operator=(const char*);
BigInt& operator+=(const BigInt&);
BigInt& operator-=(const BigInt&);
BigInt& operator*=(const BigInt&);
BigInt& operator/=(const BigInt&);
BigInt& operator%=(const BigInt&);
BigInt& operator^=(const int);
const std::string& get_value() const;
bool get_sign() const;
friend std::ostream& operator<<(std::ostream&, const BigInt&);
friend BigInt operator+(const BigInt&, const BigInt&);
friend BigInt operator-(const BigInt&, const BigInt&);
friend BigInt operator-(const BigInt&);
friend BigInt operator*(const BigInt&, const BigInt&);
friend BigInt operator/(const BigInt&, const BigInt&);
friend BigInt operator%(const BigInt&, const BigInt&);
friend BigInt operator^(const BigInt&, const int);
friend bool operator>=(const BigInt&, const BigInt&);
friend bool operator<=(const BigInt&, const BigInt&);
friend bool operator==(const BigInt&, const BigInt&);
friend bool operator!=(const BigInt&, const BigInt&);
friend bool operator>(const BigInt&, const BigInt&);
friend bool operator<(const BigInt&, const BigInt&);
friend BigInt Abs(const BigInt&);
friend BigInt Factorial(const int);
friend BigInt GCD(const BigInt&, const BigInt&);
friend BigInt LCM(const BigInt&, const BigInt&);
friend BigInt ISqrt(const BigInt&);
friend BigInt Fibonacci(const int);
friend BigInt Binomial(const int, const int);
friend bool EvenQ(const BigInt&);
friend bool OddQ(const BigInt&);
friend std::size_t IntegerLength(const BigInt&);
friend std::string Approx(const BigInt&, const std::size_t);
};
inline BigInt Add(const BigInt& x, const BigInt& y){return x + y;}
inline BigInt Subtract(const BigInt& x, const BigInt& y){return x - y;}
inline BigInt Minus(const BigInt& x){return -x;}
inline BigInt Multiply(const BigInt& x, const BigInt& y){return x * y;}
inline BigInt Divide(const BigInt& x, const BigInt& y){return x / y;}
inline BigInt Remainder(const BigInt& x, const BigInt& y){return x % y;}
inline BigInt Pow(const BigInt& x, const int y){return x ^ y;}
inline bool EqualQ(const BigInt& x, const BigInt& y){return x == y;}
inline bool NotEqualQ(const BigInt& x, const BigInt& y){return x != y;}
inline bool GreaterQ(const BigInt& x, const BigInt& y){return x > y;}
inline bool LessQ(const BigInt& x, const BigInt& y){return x < y;}
inline bool GreaterEqualQ(const BigInt& x, const BigInt& y){return x >= y;}
inline bool LessEqualQ(const BigInt& x, const BigInt& y){return x <= y;}
BigInt Abs(const BigInt&);
BigInt Factorial(const int);
BigInt GCD(const BigInt&, const BigInt&);
BigInt LCM(const BigInt&, const BigInt&);
BigInt ISqrt(const BigInt&);
BigInt Fibonacci(const int);
BigInt Binomial(const int, const int);
bool EvenQ(const BigInt&);
bool OddQ(const BigInt&);
std::size_t IntegerLength(const BigInt&);
std::string Approx(const BigInt&, const std::size_t = 10ull);
class BigFrac
{
private:
BigInt num;
BigInt denom{"1"};
public:
BigFrac()=default;
BigFrac(const BigInt&, const BigInt&);
const BigInt& get_numerator() const;
const BigInt& get_denominator() const;
friend std::ostream& operator<<(std::ostream&, const BigFrac&);
BigFrac& operator+=(const BigFrac&);
BigFrac& operator-=(const BigFrac&);
BigFrac& operator*=(const BigFrac&);
BigFrac& operator/=(const BigFrac&);
BigFrac& operator^=(const int);
friend BigFrac operator+(const BigFrac&, const BigFrac&);
friend BigFrac operator-(const BigFrac&, const BigFrac&);
friend BigFrac operator-(const BigFrac&);
friend BigFrac operator*(const BigFrac&, const BigFrac&);
friend BigFrac operator/(const BigFrac&, const BigFrac&);
friend BigFrac operator^(const BigFrac&, const int);
friend bool operator>=(const BigFrac&, const BigFrac&);
friend bool operator<=(const BigFrac&, const BigFrac&);
friend bool operator==(const BigFrac&, const BigFrac&);
friend bool operator!=(const BigFrac&, const BigFrac&);
friend bool operator>(const BigFrac&, const BigFrac&);
friend bool operator<(const BigFrac&, const BigFrac&);
friend BigFrac Abs(const BigFrac&);
friend BigFrac Harmonic(const int);
friend std::string Approx(const BigFrac&);
};
inline BigFrac Add(const BigFrac& x, const BigFrac& y){return x + y;}
inline BigFrac Subtract(const BigFrac& x, const BigFrac& y){return x - y;}
inline BigFrac Minus(const BigFrac& x){return -x;}
inline BigFrac Multiply(const BigFrac& x, const BigFrac& y){return x * y;}
inline BigFrac Divide(const BigFrac& x, const BigFrac& y){return x / y;}
inline BigFrac Pow(const BigFrac& x, const int y){return x ^ y;}
inline bool EqualQ(const BigFrac& x, const BigFrac& y){return x == y;}
inline bool NotEqualQ(const BigFrac& x, const BigFrac& y){return x != y;}
inline bool GreaterQ(const BigFrac& x, const BigFrac& y){return x > y;}
inline bool LessQ(const BigFrac& x, const BigFrac& y){return x < y;}
inline bool GreaterEqualQ(const BigFrac& x, const BigFrac& y){return x >= y;}
inline bool LessEqualQ(const BigFrac& x, const BigFrac& y){return x <= y;}
BigFrac Abs(const BigFrac&);
BigFrac Harmonic(const int);
std::string Approx(const BigFrac&);