-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigInt.hpp
92 lines (76 loc) · 3.16 KB
/
BigInt.hpp
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
#include <string>
#include <vector>
#include <limits>
typedef int i31;
typedef unsigned int i32;
typedef long long i63;
typedef unsigned long long i64;
// optimised for time, not space
// the upper is 2**M64 or 2**(2**64-1) or 10**(10**19)
// realistically you will run out of memory first, lol
class BigInt {
public:
bool isPos = true;
std::vector<i63> chunks;
BigInt();
BigInt(i31);
BigInt(i32);
BigInt(i63);
BigInt(i64);
BigInt(std::vector<i63>, bool);
BigInt(std::string);
BigInt(std::vector<bool>, bool);
BigInt(const BigInt& cp);
bool operator==(BigInt o);
template<typename T> bool operator==(T o) { return *this == BigInt(o); };
bool operator!=(BigInt o);
template<typename T> bool operator!=(T o) { return *this != BigInt(o); };
bool operator>(BigInt o);
template<typename T> bool operator>(T o) { return *this > BigInt(o); };
bool operator>=(BigInt o);
template<typename T> bool operator>=(T o) { return *this >= BigInt(o); };
bool operator<(BigInt o);
template<typename T> bool operator<(T o) { return *this < BigInt(o); };
bool operator<=(BigInt o);
template<typename T> bool operator<=(T o) { return *this <= BigInt(o); };
BigInt operator+(BigInt o);
template<typename T> BigInt operator+(T o) { return *this + BigInt(o); };
template<typename T> void operator++(T o) { *this = *this + 1; };
template<typename T> void operator+=(T o) { *this = *this + BigInt(o); };
BigInt operator-();
BigInt operator-(BigInt o);
template<typename T> BigInt operator-(T o) { return *this - BigInt(o); };
template<typename T> void operator--(T o) { *this = *this - 1; };
template<typename T> void operator-=(T o) { *this = *this - BigInt(o); };
BigInt operator*(BigInt o);
template<typename T> BigInt operator*(T o) { return *this * BigInt(o); };
template<typename T> void operator*=(T o) { *this = *this * BigInt(o); };
bool isEven();
BigInt pow(i64 o);
BigInt pow(BigInt o);
template<typename T> BigInt pow(T o) {
if (o <= std::numeric_limits<i64>::max()) return pow(i64(o));
return this->pow(BigInt(o));
};
BigInt operator<<(BigInt o);
template<typename T> BigInt operator<<(T o) { return *this << BigInt(o); };
template<typename T> void operator<<=(T o) { *this = *this << o; };
BigInt operator>>(BigInt o);
template<typename T> BigInt operator>>(T o) { return *this >> BigInt(o) ; };
template<typename T> void operator>>=(T o) { *this = *this >> o; };
BigInt abs();
i63 toLL();
bool toBool();
std::vector<bool> toBin();
BigInt operator|(BigInt o);
template<typename T> BigInt operator|(T o) { return *this | BigInt(o); };
template<typename T> void operator|=(T o) { *this = *this | BigInt(o); };
BigInt operator^(BigInt o);
template<typename T> BigInt operator^(T o) { return *this ^ BigInt(o); };
template<typename T> void operator^=(T o) { *this = *this ^ BigInt(o); };
BigInt operator&(BigInt o);
template<typename T> BigInt operator&(T o) { return *this & BigInt(o); };
template<typename T> void operator&=(T o) { *this = *this & BigInt(o); };
};
std::ostream& operator<<(std::ostream& out, BigInt obj);
std::istream& operator>>(std::istream& in, BigInt &obj);