private boolean isPrime(int len, int pos, int x, int y, boolean[] sieve) {
    
        if (pos + x < 0) return false;
        if (pos + x >= len + y) return false;
        
        switch(y) {
        case -2: return !sieve[pos + x + 0 * len - 0];
        case -1: return !sieve[pos + x + 1 * len - 2];
        case  0: return !sieve[pos + x + 2 * len - 3];
        case  1: return !sieve[pos + x + 3 * len - 3];
        case  2: return !sieve[pos + x + 4 * len - 2];
        }
        
        throw new IllegalArgumentException();
    }