//Finds factors of a given number.
public static Stream<Natural> factor(final Natural n, final Natural p, final P1<Stream<Natural>> ps) {
Stream<Natural> ns = cons(p, ps);
Stream<Natural> ret = nil();
while (ns.isNotEmpty() && ret.isEmpty()) {
final Natural h = ns.head();
final P1<Stream<Natural>> t = ns.tail();
if (naturalOrd.isGreaterThan(h.multiply(h), n))
ret = single(n);
else {
final V2<Natural> dm = n.divmod(h);
if (naturalOrd.eq(dm._2(), ZERO))
ret = cons(h, new P1<Stream<Natural>>() {