Roger Hui wrote:
>> There are a lot of alternatives based on the range you want.
>
> Some popular ranges would be
> y<2^31
> y<2^32
> y<2^63
> y<2^64
With no code conservation, here are a couple of examples.
time=:6!:2
huo=: <[EMAIL PROTECTED]:^:(0=2&|)^:a: NB. halve until odd
DMR=: 3 : 0"0 NB. up to 2^32
h=.huo y-1
s=.#h
d=.{: h
for_a. (#~ y&>) 2 7 61 do.
c=.a y&|@^d*2 y&|@^ i.s
if. (1~: {. c) *. *./ (y-1)~: c do. 0 return. end.
end.
1
)
DMR2=: 3 : 0"0 NB. up to 2^48
h=.huo y-1
s=.#h
d=.{: h
for_a. (#~ y&>) 2 3 5 7 11 13 do.
c=.a y&|@^d*2 y&|@^ i.s
if. (1~: {. c) *. *./ (y-1)~: c do. 0 return. end.
end.
1
)
N=:(i.1e3)+10^12x
time 'DMR2 N'
1.05322
time '1&p: N'
1.49582
(DMR2-:1&p:) N
1
Best wishes,
John
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm