10 ! Factor numbers in a crude way option arithmetic integer DO gosub GET_NUMBER if n < 2 then EXIT DO t1 = time(1) gosub FACTOR_IT print 'CPU time used:'; (time(1) - t1) / 10. LOOP stop GET_NUMBER: input "Number to test (0 to stop)": n if n = 1 then n = 126990991 RETURN FACTOR_IT: prime = true !** Special case for 2 ** i = 2 gosub SHOW_FACTORS !** start with first odd ** i = 3 DO found_factor = false for i = i to sqr (n) step 2 if n = n / i * i then gosub SHOW_FACTORS found_factor = true iterate do end if next i LOOP WHILE found_factor if prime then print n;'is prime' else if n = 1 then print else print n RETURN SHOW_FACTORS: DO WHILE n = n / i * i if prime then print n;"has factors";i; else print i; n = n / i prime = false LOOP RETURN