allocate mem(2^30) \\ describe a fraction: \\ - integer part \\ - transient part \\ - periodic part fracdigits(v, base=10) = { \\ integer part my (int=digits(floor(v), base)); \\ period length my (den=denominator(v), pr=factor(base)[,1]~, p=znorder(Mod(base, den / prod(i=1, #pr, pr[i]^valuation(den,pr[i]))))); \\ transient part my (tra=[], fra=frac(v)); while (fra != frac(fra*base^p), tra = concat(tra, floor(fra*base)); fra = frac(fra*base); ); \\ periodic part my (per = vector(p, x, my (d=floor(fra*base)); fra = frac(fra*base); d)); return ([int,tra,per]); } \\ rebuild a fraction fromfracdigits(f, base=10) = fromdigits(f[1],base) + ( fromdigits(f[2],base) + fromdigits(f[3],base)/base^#f[3] / (1-1/base^#f[3])) / base^#f[2]; is(n) = { my (f = fracdigits(1/n)); if (vecmin(f[3]), my (t = concat(f[1], f[2])); for (k = 1, #t, if (t[k], return (vecmin(t[k..#t])); ); ); return (1), return (0) ); } { k = 0; for (n = 1, oo, if (is(n), print (k++ " " n); if (n==10 000, break; ); ); ); } quit