コード例 #1
0
 static Generic factorize(JsclInteger integer) {
   Generic n[] = integer.gcdAndNormalize();
   Generic s = n[1];
   Generic a = JsclInteger.valueOf(1);
   Generic p = JsclInteger.valueOf(2);
   while (s.compareTo(JsclInteger.valueOf(1)) > 0) {
     Generic q[] = s.divideAndRemainder(p);
     if (q[0].compareTo(p) < 0) {
       p = s;
       q = s.divideAndRemainder(p);
     }
     if (q[1].signum() == 0) {
       a = a.multiply(expression(p, true));
       s = q[0];
     } else p = p.add(JsclInteger.valueOf(1));
   }
   return a.multiply(n[0]);
 }
コード例 #2
0
 static Generic expression(Generic generic, boolean integer) {
   if (generic.compareTo(JsclInteger.valueOf(1)) == 0) return generic;
   else return GenericVariable.valueOf(generic, integer).expressionValue();
 }