/* here's a good test command script: /* .[int q;for (q=32742;q<=32766;++q) [factortest q;pl "";sak;pl ""]] /* factor.tc - 1/26/2010 - tct /* since the sqrt of 32767 is less than 182, all prime factors of numbers /* less than 32767 are less than 191, the 43rd prime. factor int f [ /* returns smallest factor of f int p(42),j p(0)=2;p(1)=3;p(2)=5;p(3)=7;p(4)=11;p(5)=13;p(6)=17;p(7)=19;p(8)=23;p(9)=29;p(10)=31 p(11)=37;p(12)=41;p(13)=43;p(14)=47;p(15)=53;p(16)=59;p(17)=61;p(18)=67;p(19)=71 p(20)=73;p(21)=79;p(22)=83;p(23)=89;p(24)=97;p(25)=101;p(26)=103;p(27)=107;p(28)=109 p(29)=113;p(30)=127;p(31)=131;p(32)=137;p(33)=139;p(34)=149;p(35)=151;p(36)=157 p(37)=163;p(38)=167;p(39)=173;p(40)=179;p(41)=181;p(42)=191 for (j=0;j<=42;++j) if (f/p(j)*p(j)==f) return p(j) /* must be composite return f /* must be prime ] factortest int t [ pl "factor.tc - 1/26/2010 - tct";pl "";pl "" int i,j i=t while ((j=factor(i))!=i) [pn j;ps " *";i=i/j] pn i;pl "" ]