-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodulo.cpp
More file actions
71 lines (53 loc) · 1.2 KB
/
modulo.cpp
File metadata and controls
71 lines (53 loc) · 1.2 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
#include "modulo.h"
BigInt abs(const BigInt& a){
if (a > 0 || a == 0){
return a;
}
return -a;
}
modulo::modulo(const BigInt& res) {
if (res > 0){
BigInt tmp = res;
while (tmp > n){
tmp = tmp - n;
}
this_value = tmp;
}
else {
BigInt tmp = res;
while (tmp < 0){
tmp = tmp + n;
}
this_value = tmp;
}
}
modulo::modulo(const modulo& res){
this_value = res.this_value;
}
modulo::modulo(){
this_value = 0;
}
modulo::~modulo(){
}
modulo& modulo:: operator = (const modulo& res){
this_value = res.this_value;
return *this;
}
std::ostream & operator << (std::ostream & out, const modulo & res){
std::cout<<res.this_value;
return out;
}
int operator == (const modulo& left, const modulo& right){
if (left.this_value == right.this_value){
return 1;
}
return 0;
}
int operator != (const modulo& left, const modulo& right){
return !(left == right);
}
modulo operator + (const modulo& left, const modulo& right){
std::cout<<left.this_value<<" "<<right.this_value<<'\n';
modulo res(left.this_value + right.this_value);
return res;
}