I have used the wrong terminology. I want to find all the positive integer *divisors* of an integer n (not just primes) which includes 1 and the integer. Here's a brute force verb I wrote: div=:3 : 'a#~0=(a=.1+i.y)|y'
Test it: div each 40+i.5 │1 2 4 5 8 10 20 40│1 41│1 2 3 6 7 14 21 42│1 43│1 2 4 11 22 44│ However my div verb is inefficient, slow, and runs out of memory quickly on larger integers. Is there a way to take advantage of J's prime factoring verb q: to more efficiently find and/or count *all* positive divisors (not just primes) of a large (>1e7) integers? Skip Skip Cave Cave Consulting LLC Skip Cave Cave Consulting LLC On Fri, Apr 24, 2020 at 1:31 PM Roger Hui <[email protected]> wrote: > See https://code.jsoftware.com/wiki/Essays/Factorings > > > > On Fri, Apr 24, 2020 at 11:29 AM Skip Cave <[email protected]> > wrote: > > > I want to find all the integer factors of a positive integer, > > which includes 1 and the integer. > > Here's a brute force verb I wrote: > > fac=:3 : 'a#~0=(a=.1+i.y)|y' > > > > Test it: > > > > fac each 40+i.5 > > > > │1 2 4 5 8 10 20 40│1 41│1 2 3 6 7 14 21 42│1 43│1 2 4 11 22 44│ > > > > > > However my fac verb is inefficient, slow, and runs out of memory quickly > on > > larger integers. Is there a way to take advantage of J's prime factoring > > verb q: to more efficiently find and/or count *all* positive factors (not > > just primes) of a large (>1e7) integers? > > > > > > Skip > > > > > > Skip Cave > > Cave Consulting LLC > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
