public void primesToMax() {
    primes = new HashSet<Integer>();
    int[] sieve = new int[MAX];
    int ceiling = (int) Math.sqrt(MAX);
    for (int i = 2; i < MAX; i++)
      sieve[i] = 1;
    for (int i = 2; i < ceiling; i++)
      for (int j = 2; i*j < MAX; j++)
        if (sieve[i*j] == 1)
          sieve[i*j] = 0;
    for (int i = 2; i < MAX; i++)
      if (sieve[i] == 1 && !primes.contains(i))
        primes.add(i);
  }