public static int[] getPrimes(int max) {
		int[] primes = new int[max+1];
		
		// populate with all number between 2 to max
		for (int i = 2; i <= max; i++) {
			primes[i] = i;
		}

		int total = max-1;
		for (int i = 2; i <= Math.sqrt(max); i++) {
			// remove the succeeding multiples of a base number
			for (int j = i; j <= max;) {
				j += i;
				if (j <= max && primes[j] > 0) {
					primes[j] = 0;
					total--;
				}
			}
		}
		
		// copy primes from the larger array to the smaller array
		int[] totalprimes = new int[total];
		int temp = 0;
		for (int i = 0; i < primes.length; i++) {
			if (primes[i] > 0) {
				totalprimes[temp] = primes[i];
				temp++;
			}
		}
		
		return totalprimes;
	}