10-09-2005, 10:24 PM
Neuro's entry takes ages to factorize 2123456783, it issues a 7 at the start then it stands for a while.
I tried to modify it to make it faster, by not checking 2 and 3 multiples and stopping when the factor is equal to the square root of the remainder. Here is the result, 25 lines at all.
I tried to modify it to make it faster, by not checking 2 and 3 multiples and stopping when the factor is equal to the square root of the remainder. Here is the result, 25 lines at all.
Code:
declare sub checkf(k&)
dim shared x&
do
print
INPUT "enter a number to factorize[0 to end] : ", x&
if x&=0 then exit do
PRINT "the prime factors are:";
checkf(2)
checkf(3)
a&=2
k& = 3 + a&
WHILE k& <=int(sqr(x&))
checkf(k&)
k& = k& + a&
a&=6&-a&
WEND
if x&>1 then print x&;
loop
PRINT "Ended"
sub checkf(k&)
WHILE x& MOD k& = 0
x& = x& \ k&
PRINT k&;
WEND
end sub
Antoni