-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpInt.cpp
More file actions
234 lines (174 loc) · 5.85 KB
/
Copy pathpInt.cpp
File metadata and controls
234 lines (174 loc) · 5.85 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
Copyright © 2024 Claus Vind - Andreasen
This program is free software; you can redistribute it and /or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 - 1307 USA
This General Public License does not permit incorporating your program into proprietary programs.If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library.
If this is what you want to do, use the GNU Library General Public License instead of this License.
*/
// pInt.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include "pIntClass.h"
#include "pIntClassUtil.h"
#ifdef PERF
#include "windows.h"
#include "profileapi.h"
#endif
void test13QuotientReminder()
{
pIntClass num1("777777777777777");
pIntClass num("5555555555555");
#define LIMIT1 100000
#define STEP 177395769
for (int i = 0; i < LIMIT1; i++)
{
pIntClass t1 = num1;
pIntClass t = num;
pIntClass step(STEP);
pIntClass Quotient;
pIntClass Remainder;
step *= i;
t += step;
Remainder =RemQuotient(t1, t, &Quotient);
t = num;
step = STEP;
step *= i;
t += step;
std::cout << "Quotient: " << Quotient.ToString() << std::endl;
t *= Quotient;
t += Remainder;
if (num1 != t) {
std::cout << "num * Quotient + Remainder: " << t.ToString() << std::endl;
std::cout << "Num1 : " << num1.ToString() << std::endl;
}
}
}
void test15Jacobi()
{
for (int j = 3; j < 60; j += 2)
for (int i = 1; i < 31; i++) {
std::cout << "Jacobi ( ";
pIntClass cj(j);
pIntClass ci(i);
std::cout << ci.ToString() << "/ ";
std::cout << cj.ToString() << " ) = ";
std::cout << Jacobi( ci, cj) << std::endl;
}
}
void testSubtraction();
void testAddition();
void testMultiplication();
void testTonelliShanks();
void testMR();
void testModMult();
void testpIntClass2(){
pIntClass a("4999999999999999999999999999");
pIntClass b("5000000000000000000000000000");
pIntClass a1(a);
pIntClass b1(b);
std::cout << "1 a1: " << a1.ToString() << std::endl;
std::cout << "2 b1: " << b1.ToString() << std::endl;
a1 -= b1;
std::cout << "3 a1: " << a1.ToString() << std::endl;
std::cout << "4 b1: " << b1.ToString() << std::endl;
a1 += b1;
std::cout << "5 a1: " << a1.ToString() << std::endl;
std::cout << "6 b1: " << b1.ToString() << std::endl;
--b1;
a1 -= b1;
std::cout << "7 a1: " << a1.ToString() << std::endl;
std::cout << "8 b1: " << b1.ToString() << std::endl;
a1 = a;
b1 = b;
a1 = b + b;
b1 = b1 + b1;
std::cout << "9 a1: " << a1.ToString() << std::endl;
std::cout << "10 b1: " << b1.ToString() << std::endl;
a1 = pIntClass("4999999999");
b1 = b;
a1 = a1 + a1;
b1 = a1 + b1;
std::cout << "11 a1: " << a1.ToString() << std::endl;
std::cout << "12 b1: " << b1.ToString() << std::endl;
a1 = pIntClass("4999999999");
b1 = b;
std::cout << "13 a1: " << a1.ToString() << std::endl;
std::cout << "14 b1: " << b1.ToString() << std::endl;
a1 = a1 + a1;
std::cout << "15 a1: " << a1.ToString() << std::endl;
b1 = a;
std::cout << "16 b1: " << b1.ToString() << std::endl;
b1 += a1;
std::cout << "17 b1: " << b1.ToString() << std::endl;
b1 += b1;
std::cout << "18 b1: " << b1.ToString() << std::endl;
b1 += 7;
std::cout << "19 b1: " << b1.ToString() << std::endl;
b1 += 10;
std::cout << "20 b1: " << b1.ToString() << std::endl;
a1 = pIntClass("4999999999");
b1 = b;
std::cout << "21 a1: " << a1.ToString() << std::endl;
std::cout << "22 b1: " << b1.ToString() << std::endl;
a1 = a1 + a1;
std::cout << "23 a1: " << a1.ToString() << std::endl;
b1 = a + a1 ;
std::cout << "24 b1: " << b1.ToString() << std::endl;
b1 = b1 + b1 + 7 + 10;
std::cout << "25 b1: " << b1.ToString() << std::endl;
}
void testExponentiation()
{
pIntClass res;
res = exponentiation(2, 86243);
--res;
std::cout << "res: " << res.ToString() << std::endl;
res = exponentiation(2, 1257787);
--res;
std::cout << "res: " << res.ToString() << std::endl;
res = exponentiation(2, 3021377);
--res;
std::cout << "res: " << res.ToString() << std::endl;
res = exponentiation(2, 20996011);
--res;
std::cout << "res: " << res.ToString() << std::endl;
}
#define TESTLENGTH 100
void testLeaks()
{
pIntClass* A = new pIntClass();
for (int i = 0; i < TESTLENGTH; i++)
{
delete A;
A = new pIntClass();
*A = 100;
std::string s;
s = A->ToString();
++(*A);
std::cout << "A " << A->ToString() << std::endl;
}
for (int i = 0; i < TESTLENGTH; i++)
{
delete A;
A = new pIntClass();
*A = (*A) + 7;
*A *= 100;
*A = (*A) * 100;
std::string s;
s = A->ToString();
std::cout << "A " << A->ToString() << std::endl;
}
delete A;
}
int main()
{
testLeaks();
testMR();
testExponentiation();
testSubtraction();
testAddition();
testMultiplication();
testModMult();
testTonelliShanks();
}