code: private static int mod(int a, final int B) {
          final int N = a / B;
  
          a -= N * B;
          if (a < 0) {
              return a + B;
          }
          return a;
      }
docs: Return a mod b. This differs from the % operator with respect to negative numbers.
  @param a the dividend
  @param B the divisor
  @return a mod b