Re: TIB: Looking for prime factorization code


[Prev][Next][Index][Thread]

Re: TIB: Looking for prime factorization code



Kåre Krig wrote:
> 
> At 15:36 1997-10-01 -0700, you wrote:
> >Does anyone have a program for finding the prime factorization of a
> >number?
> >
> I made a program for that seme time ago.
> 
> It divides the number with two and checks if the fPart of the answer equals
> 0, if it does it can be divided with two.
> After dividing with two it tryes the same for all odd numbers upp to the
> square root of the original number.

wouldn't this be a whole lot easier:

:primef(n)
:Prgm
:if n<>int(n)
:stop
:Local i
:2->i
:While n>1
:While mod(n,i) <> 0
:i+1->i
:EndWhile
:n/i->n

  output your i here, in any form desirable

:EndWhile
:EndPrgm

  ?

or...?
If your version is more efficient, please explain to me how and why, I'd
be very interested to know if this could be done more efficiently.

With kind regards,

-- 
          Rene Kragh Pedersen
--------------------------------------------------------------------
.oO) It's not reality that matters, it's how you percieve things (Oo.


References: