-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbigInteger.h
More file actions
128 lines (99 loc) · 3.99 KB
/
bigInteger.h
File metadata and controls
128 lines (99 loc) · 3.99 KB
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
#pragma once
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
class BigInteger {
private:
enum Signs { MINUS = -1, PLUS = 1 };
std::vector<long long> number_;
static const int base_ = 1e9;
static const int b_cnt_ = 9;
int sign_;
friend void swap(BigInteger& number1, BigInteger& number2);
static void borrow(std::vector<long long>& number, int to);
static void cut(std::vector<long long>& number);
void fix(bool is_changed = true);
static std::pair<int, BigInteger> DivBinsearch(
std::vector<long long>& divisible,
const std::vector<long long>& divider, int lower_bit, int higher_bit);
void clear();
void subtrOrAdd(const BigInteger& number, int operation);
void subtrOrAddSameSign(const BigInteger& number);
void subtrOrAddPosSign(const BigInteger& number);
void subtrOrAddNegSign(const BigInteger& number);
void modOrDiv(const BigInteger& number, bool to_mod);
public:
BigInteger(int number);
BigInteger(const char* number, size_t sz = 0);
BigInteger();
explicit operator bool() const;
std::string toString() const;
const std::vector<long long>& getData() const;
int getSize() const;
int getSign() const;
void setSign(int sign) {
sign_ = sign;
}
static int getBase();
BigInteger& operator+=(const BigInteger& number);
BigInteger& operator-=(const BigInteger& number);
BigInteger& operator*=(const BigInteger& number);
BigInteger& operator/=(const BigInteger& number);
BigInteger& operator%=(const BigInteger& number);
BigInteger operator-() const;
BigInteger operator+() const;
BigInteger& operator++();
BigInteger operator++(int);
BigInteger& operator--();
BigInteger operator--(int);
};
BigInteger operator""_bi(unsigned long long number);
BigInteger operator""_bi(const char* number, unsigned long sz);
bool operator<(const BigInteger& a, const BigInteger& b);
bool operator==(const BigInteger& a, const BigInteger& b);
bool operator>(const BigInteger& a, const BigInteger& b);
bool operator<=(const BigInteger& a, const BigInteger& b);
bool operator>=(const BigInteger& a, const BigInteger& b);
bool operator!=(const BigInteger& a, const BigInteger& b);
BigInteger operator+(const BigInteger& a, const BigInteger& b);
BigInteger operator-(const BigInteger& a, const BigInteger& b);
BigInteger operator*(const BigInteger& a, const BigInteger& b);
BigInteger operator/(const BigInteger& a, const BigInteger& b);
BigInteger operator%(const BigInteger& a, const BigInteger& b);
class Rational {
private:
BigInteger numerator_;
BigInteger denominator_;
void shorten();
static BigInteger gcd(const BigInteger& a, const BigInteger& b);
void swap(Rational& frac);
void subtrOrAdd(const Rational& frac, bool to_substr);
public:
Rational(const BigInteger& num, const BigInteger& den = 1);
Rational();
Rational(int number);
friend bool operator<(const Rational& a, const Rational& b);
Rational operator-() const;
Rational operator+() const;
Rational& operator+=(const Rational& frac);
Rational& operator*=(const Rational& frac);
Rational& operator/=(const Rational& frac);
Rational& operator-=(const Rational& frac);
explicit operator double();
std::pair<BigInteger, BigInteger> getData() const {
return std::make_pair(numerator_, denominator_);
}
std::string toString() const;
std::string asDecimal(size_t precision = 20) const;
};
bool operator==(const Rational& a, const Rational& b);
bool operator!=(const Rational& a, const Rational& b);
bool operator>(const Rational& a, const Rational& b);
bool operator>=(const Rational& a, const Rational& b);
bool operator<=(const Rational& a, const Rational& b);
Rational operator+(const Rational& a, const Rational& b);
Rational operator-(const Rational& a, const Rational& b);
Rational operator*(const Rational& a, const Rational& b);
Rational operator/(const Rational& a, const Rational& b);