PMath { public static void factors(long value, byte[] target, int offset, int length, int mask) { int pIndex = 0; do { int exponent = 0; if (1 != value) { int p = primeAtIdx(pIndex++); boolean continueCheck = false; do { long d = value/p; long r = value%p; if (r==0) { value = d; exponent++; continueCheck = (d!=1); } else { continueCheck = false; } } while (continueCheck); } target[mask&offset++] = (byte)exponent; } while (--length>0); }  static void factors(long value, byte[] target, int offset, int length, int mask); static void greatestCommonFactor( byte[] backingA, int offsetA, int lengthA, int maskA,
                                             byte[] backingB, int offsetB, int lengthB, int maskB,
                                             byte[] target,   int offset, int length, int mask); static void greatestCommonFactor( byte[][] backingA, int[] offsetA, int[] lengthA, int[] maskA,
                                             byte[] target, int offset, int length, int mask); static void removeFactors( byte[] backingA, int offsetA, int lengthA, int maskA,
                                     byte[] backingB, int offsetB, int lengthB, int maskB,
                                     byte[] target,   int offset, int length, int mask); static void removeExistingFactors( byte[] backingA, int offsetA, int lengthA, int maskA,
                                             byte[] backingB, int offsetB, int lengthB, int maskB,
                                             byte[] target,   int offset, int length, int mask); static void addFactors( byte[] backingA, int offsetA, int lengthA, int maskA,
                                  byte[] backingB, int offsetB, int lengthB, int maskB,
                                  byte[] target,   int offset, int length, int mask); static int factorsToInt(byte[] target, int offset, int length, int mask); static long factorsToLong(byte[] target, int offset, int length, int mask); static int nextPrime(int startValue); static ScriptedSchedule buildScriptedSchedule(long[] schedulePeriods); static ScriptedSchedule buildScriptedSchedule(long[] schedulePeriods, final boolean reverseOrder);  }
@Test public void testFactors() { int length = 5; byte[] target = new byte[length]; PMath.factors(120, target, 0, length, Integer.MAX_VALUE); assertTrue(Arrays.toString(target),Arrays.equals(new byte[]{3,1,1,0,0}, target)); assertEquals(120,PMath.factorsToInt(target, 0, length, Integer.MAX_VALUE)); PMath.factors(80, target, 0, length, Integer.MAX_VALUE); assertTrue(Arrays.toString(target),Arrays.equals(new byte[]{4,0,1,0,0}, target)); assertEquals(80,PMath.factorsToInt(target, 0, length, Integer.MAX_VALUE)); length = 33; target = new byte[33]; PMath.factors(131*2, target, 0, length, Integer.MAX_VALUE); assertTrue(Arrays.toString(target),Arrays.equals(new byte[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, target)); assertEquals(131*2,PMath.factorsToInt(target, 0, length, Integer.MAX_VALUE)); }