# [SPOJ] PRIME1 – Prime Generator

```public void solve(int testNumber, InputReader in, OutputWriter out) {
for (int i = 0; i < t; i++) {
if (m < 2) m = 2;
prime(m,n,out);
out.printLine();
}
}
public void prime(int m, int n,OutputWriter out) {
int range = (int)Math.floor(Math.sqrt(n));
boolean[] prime = new boolean[range];
Arrays.fill(prime, 2, prime.length, true);
for (int i = 2; i< range; i++)
if (prime[i])
for (int j = i * i; j < range; j += i)
prime[j] = false;
int[] primes = new int[range + 1];
int cnt = 0;
for (int i = 0; i < prime.length; i++)
if (prime[i])
primes[cnt++] = i;

boolean[] p = new boolean[n-m+1];
Arrays.fill(p,true);
for (int i = 0; i < cnt; i++) {
if (primes[i] == 0)
break;
int low = m / primes[i] * primes[i];
for (int j = low; j <= n; j+=primes[i]) {
if (j < m)
continue;
p[j-m] = false;
}
}
for (int i = 0; i < cnt; i++) {
if (m<=primes[i]&&primes[i]<=n)
out.printLine(primes[i]);
}
for (int i = 0; i < n-m+1; i++) {
if (p[i] && (i+m)!=1)
out.printLine(i+m);
}

}```