11package algolib .maths ;
22
3- /** Algorithms for basic mathematical operations . */
4- public final class Maths
3+ /** Algorithms for basic computations on integers . */
4+ public final class Integers
55{
66 // region gcd
77
@@ -63,7 +63,7 @@ public static int lcm(int number1, int number2)
6363 int min_number = Math .min (Math .abs (number1 ), Math .abs (number2 ));
6464 int max_number = Math .max (Math .abs (number1 ), Math .abs (number2 ));
6565
66- return max_number / Maths .gcd (number1 , number2 ) * min_number ;
66+ return max_number / Integers .gcd (number1 , number2 ) * min_number ;
6767 }
6868
6969 /**
@@ -77,7 +77,7 @@ public static long lcm(long number1, long number2)
7777 long min_number = Math .min (Math .abs (number1 ), Math .abs (number2 ));
7878 long max_number = Math .max (Math .abs (number1 ), Math .abs (number2 ));
7979
80- return max_number / Maths .gcd (number1 , number2 ) * min_number ;
80+ return max_number / Integers .gcd (number1 , number2 ) * min_number ;
8181 }
8282
8383 // endregion
@@ -94,13 +94,13 @@ public static int multiply(int factor1, int factor2)
9494 int result = 0 ;
9595
9696 if (factor1 < 0 && factor2 < 0 )
97- return Maths .multiply (-factor1 , -factor2 );
97+ return Integers .multiply (-factor1 , -factor2 );
9898
9999 if (factor1 < 0 )
100- return -Maths .multiply (-factor1 , factor2 );
100+ return -Integers .multiply (-factor1 , factor2 );
101101
102102 if (factor2 < 0 )
103- return -Maths .multiply (factor1 , -factor2 );
103+ return -Integers .multiply (factor1 , -factor2 );
104104
105105 while (factor2 > 0 )
106106 {
@@ -125,13 +125,13 @@ public static long multiply(long factor1, long factor2)
125125 long result = 0 ;
126126
127127 if (factor1 < 0 && factor2 < 0 )
128- return Maths .multiply (-factor1 , -factor2 );
128+ return Integers .multiply (-factor1 , -factor2 );
129129
130130 if (factor1 < 0 )
131- return -Maths .multiply (-factor1 , factor2 );
131+ return -Integers .multiply (-factor1 , factor2 );
132132
133133 if (factor2 < 0 )
134- return -Maths .multiply (factor1 , -factor2 );
134+ return -Integers .multiply (factor1 , -factor2 );
135135
136136 while (factor2 > 0 )
137137 {
@@ -160,13 +160,13 @@ public static int multiply(int factor1, int factor2, int modulo)
160160 throw new ArithmeticException ("Non-positive modulo" );
161161
162162 if (factor1 < 0 && factor2 < 0 )
163- return Maths .multiply (-factor1 , -factor2 , modulo );
163+ return Integers .multiply (-factor1 , -factor2 , modulo );
164164
165165 if (factor1 < 0 )
166- return modulo - Maths .multiply (-factor1 , factor2 , modulo );
166+ return modulo - Integers .multiply (-factor1 , factor2 , modulo );
167167
168168 if (factor2 < 0 )
169- return modulo - Maths .multiply (factor1 , -factor2 , modulo );
169+ return modulo - Integers .multiply (factor1 , -factor2 , modulo );
170170
171171 while (factor2 > 0 )
172172 {
@@ -195,13 +195,13 @@ public static long multiply(long factor1, long factor2, long modulo)
195195 throw new ArithmeticException ("Non-positive modulo" );
196196
197197 if (factor1 < 0 && factor2 < 0 )
198- return Maths .multiply (-factor1 , -factor2 , modulo );
198+ return Integers .multiply (-factor1 , -factor2 , modulo );
199199
200200 if (factor1 < 0 )
201- return modulo - Maths .multiply (-factor1 , factor2 , modulo );
201+ return modulo - Integers .multiply (-factor1 , factor2 , modulo );
202202
203203 if (factor2 < 0 )
204- return modulo - Maths .multiply (factor1 , -factor2 , modulo );
204+ return modulo - Integers .multiply (factor1 , -factor2 , modulo );
205205
206206 while (factor2 > 0 )
207207 {
@@ -237,9 +237,9 @@ public static int power(int base, int exponent)
237237 while (exponent > 0 )
238238 {
239239 if (exponent % 2 == 1 )
240- result = Maths .multiply (result , base );
240+ result = Integers .multiply (result , base );
241241
242- base = Maths .multiply (base , base );
242+ base = Integers .multiply (base , base );
243243 exponent /= 2 ;
244244 }
245245
@@ -265,9 +265,9 @@ public static long power(long base, long exponent)
265265 while (exponent > 0 )
266266 {
267267 if (exponent % 2 == 1 )
268- result = Maths .multiply (result , base );
268+ result = Integers .multiply (result , base );
269269
270- base = Maths .multiply (base , base );
270+ base = Integers .multiply (base , base );
271271 exponent /= 2 ;
272272 }
273273
@@ -297,9 +297,9 @@ public static int power(int base, int exponent, int modulo)
297297 while (exponent > 0 )
298298 {
299299 if (exponent % 2 == 1 )
300- result = Maths .multiply (result , base , modulo );
300+ result = Integers .multiply (result , base , modulo );
301301
302- base = Maths .multiply (base , base , modulo );
302+ base = Integers .multiply (base , base , modulo );
303303 exponent /= 2 ;
304304 }
305305
@@ -329,9 +329,9 @@ public static long power(long base, long exponent, long modulo)
329329 while (exponent > 0 )
330330 {
331331 if (exponent % 2 == 1 )
332- result = Maths .multiply (result , base , modulo );
332+ result = Integers .multiply (result , base , modulo );
333333
334- base = Maths .multiply (base , base , modulo );
334+ base = Integers .multiply (base , base , modulo );
335335 exponent /= 2 ;
336336 }
337337
0 commit comments