Module Checkit { Set Fast ! Form 80, 40 Refresh Function Smith(max=10000) { Function SumDigit(a$) { def long sum For i=1 to len(a$) {sum+=val(mid$(a$,i, 1)) } =sum } x=max \\ Euler's Sieve Dim r(x+1)=1 k=2 k2=k**2 While k2x } r(0)=0 smith=0 smith2=0 lastI=0 inventory smithnumbers Top=max div 100 c=4 For i=4 to max { if c> top then print over $(0,6), ceil(i/max*100);"%" : Refresh : c=1 c++ if r(i)=0 then { smith=sumdigit(str$(i)) : lastI=i smith2=0 do { ii=int(sqrt(i))+1 do { ii-- : while r(ii)<>1 {ii--} } until i mod ii=0 if ii<2 then smith2+=sumdigit(str$(i)):exit smith3=sumdigit(str$(ii)) do { smith2+=smith3 i=i div ii : if ii<2 or i<2 then exit } until i mod ii<>0 or smith2>smith } until i<2 or smith2>smith If smith=smith2 then Append smithnumbers, lastI } } =smithnumbers } const MaxNumbers=10000 numbers= Smith(MaxNumbers) Print Print $(,5), numbers Print Print format$(" {0} smith numbers found <= {1}", Len(numbers), MaxNumbers) } Checkit