Fix legendre computation. Implement sieve range calculation.