Fix and test ProgressionUtil

Arithmetical modulo implementation was incorrect (-10 mod 1 == 0, but was 1)
This commit is contained in:
Alexander Udalov
2013-06-20 21:04:42 +04:00
parent 53cc582040
commit aea8f3bcee
2 changed files with 100 additions and 2 deletions
+4 -2
View File
@@ -22,11 +22,13 @@ public class ProgressionUtil {
// a mod b (in arithmetical sense)
private static int mod(int a, int b) {
return a >= 0 ? a % b : a % b + b;
int mod = a % b;
return mod >= 0 ? mod : mod + b;
}
private static long mod(long a, long b) {
return a >= 0 ? a % b : a % b + b;
long mod = a % b;
return mod >= 0 ? mod : mod + b;
}
// (a - b) mod c