-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility.cpp
73 lines (59 loc) · 1.78 KB
/
Utility.cpp
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
#include "Utility.h"
bool signReadStream(istream &in, long long int &sign) {
char c;
if( !in.get(c) ) {
return false;
}
else if ( c == '-' ) {
sign = -1;
return true;
}
else if ( c == '+' ) {
sign = 1;
return true;
}
in.unget();
return false;
}
unsigned long long int integerGcdComputation(unsigned long long int x, unsigned long long int y) {
if ( y == 0 ) return x;
return integerGcdComputation(y, x % y);
}
long long int integerGcd(long long int x, long long int y) {
if ( x < 0 ) x = -x;
if ( y < 0 ) y = -y;
if ( x < y ) swap(x, y);
return integerGcdComputation(x, y);
}
bool readStream_(ZZ_p &val, istream &in, bool ImplicitSign, bool &ImplicitOne) {
long long int sign = 1;
if( !ImplicitSign ) {
if ( !signReadStream(in, sign) ) {
return false;
}
}
long long int NoSign = 1;
char c;
if ( !in.get(c) ) return false; // Forse dovrei ungettare?
in.unget();
if ( ('0' <= c && c <= '9') ||
( ImplicitSign && (c == '-' || c == '+') ) ) {
ImplicitOne = false;
in >> NoSign;
}
else {
ImplicitOne = true;
}
val = to_ZZ_p( sign * NoSign );
//val = ( sign * NoSign ) % mod;
//if ( val < 0 ) val += mod;
return true;
}
/*
void writeStream(ZZ_p &val, ostream &out, bool ImplicitSign, bool ImplicitOne) {
if ( !ImplicitSign) out << '+';
if ( ImplicitOne ) {
if ( val != to_ZZ_p(1) ) out << val;
}
else out << val;
}*/