-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZNumber.hpp
84 lines (60 loc) · 2.38 KB
/
ZNumber.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
#ifndef ZNUMBER_HPP_INCLUDED
#define ZNUMBER_HPP_INCLUDED
#include <vector>
#include <ostream>
class ZNumber{
static const uint32_t module = 4294967291;//should be prime between 2^31 and 2^32
uint32_t n;
inline ZNumber getInverse() const;//вычисляет 1 / n (mod module). Расширенный алгоритм Эвклида.
public:
inline ZNumber(const int64_t n = 0){
if(n >= module)
this->n = n % module;
else if(n < 0)
this->n = module - (-n % module);
else
this->n = n;
}
ZNumber operator+(const ZNumber &zn) const;
ZNumber operator-() const;
ZNumber operator-(const ZNumber &zn) const;
ZNumber operator*(const ZNumber &zn) const;
ZNumber operator/(const ZNumber &zn) const;
ZNumber operator%(const ZNumber &zn) const;
ZNumber operator^(const ZNumber &zn) const;
const ZNumber &operator=(const ZNumber &zn);
const ZNumber &operator+=(const ZNumber &zn);
const ZNumber &operator-=(const ZNumber &zn);
const ZNumber &operator*=(const ZNumber &zn);
const ZNumber &operator/=(const ZNumber &zn);
const ZNumber &operator%=(const ZNumber &zn);
const ZNumber &operator^=(const ZNumber &zn);
ZNumber &operator++();
ZNumber operator++(int);
ZNumber &operator--();
ZNumber operator--(int);
bool operator==(const ZNumber &zn) const;
bool operator!=(const ZNumber &zn) const;
bool operator<(const ZNumber &zn) const;
bool operator>(const ZNumber &zn) const;
bool operator<=(const ZNumber &zn) const;
bool operator>=(const ZNumber &zn) const;
bool operator!() const;
bool operator&&(const ZNumber &zn) const;
bool operator||(const ZNumber &zn) const;
inline uint32_t getValue() const{
return this->n;
}
string toString() const;
};
ostream &operator<<(ostream &o, const vector<ZNumber> &v);
vector<ZNumber> operator+(const vector<ZNumber> &v1, const vector<ZNumber> &v2);
const vector<ZNumber> &operator+=(vector<ZNumber> &v1, const vector<ZNumber> &v2);
vector<ZNumber> operator-(const vector<ZNumber> &v2);
vector<ZNumber> operator-(const vector<ZNumber> &v1, const vector<ZNumber> &v2);
const vector<ZNumber> &operator-=(vector<ZNumber> &zv1, const vector<ZNumber> &zv2);
vector<ZNumber> operator*(const vector<ZNumber> &v1, const vector<ZNumber> &v2);
vector<ZNumber> operator*(vector<ZNumber> v, const ZNumber &zn);
vector<ZNumber> operator/(vector<ZNumber> v, const ZNumber &zn);
ZNumber sum(const vector<ZNumber> &v);
#endif // ZNUMBER_HPP_INCLUDED