あ、桁溢れ忘れてた。
whileの条件の中は m < sqrt(MAX3/3) で、抜けたあとに
 for(; m < MAX3; m++)
   if(!TestBits(tbl, m))
     PutsInt(m);
て感じで。
mallocの中はMAX3/7くらいで。