Does Goldbach's Conjecture hold true for other conditions?

55 Views Asked by At

I have been reading up on Goldbach's conjecture and how I understand it is as follows:

For all values of x that satisfy x % 2 == 0, where x is an element from the set of natural numbers starting at 4, x is the sum of 2 primes numbers

I was wondering is this also true?: For all values of x that satisfy x % n == 0, where x is an element from the set of natural numbers starting at n * 2, x is the sum of n primes numbers

I wrote a quick program to test this theory and so far it hasnt failed:

static int[] prime_bank;

public static void main(String[] args) {
    int size = 500;
    fillBank(size);
    int result;
    for(int i = 2; i < 100; ++i)
        if((result = isValidGoldBach(size, i)) == -1){
            System.out.println("Valid GoldBach at:" + i);
        }else{
            System.out.println("Invalid GoldBach at:" + i + " (number:" + result + ")");
        }
}

private static int isValidGoldBach(int max_value, int div){
    for(int i = div * 2; i < max_value; i += div){
        if(!checkGoldBach(i, div)) return i;
    }
    return -1;
}

private static boolean _checkGoldBach(int number, int div, int curr, int[] buffer){
    if(curr < div){
        for (int i : prime_bank) {
            buffer[curr] = i;
            if(_checkGoldBach(number, div, curr + 1, buffer)) return true;
        }
    }else{
        int sum = 0;
        for(int i : buffer)sum += i;
        return sum == number;
    }
    return false;
}

private static boolean checkGoldBach(int number, int div){
    return _checkGoldBach(number, div, 0, new int[div]);
}

private static void fillBank(int size){
    prime_bank = new int[size];
    if(size > 0) prime_bank[0] = 2;
    int idx = 1;
    for(int i = 3; idx < size; i += 2){
        if(isPrime(i)){
            prime_bank[idx++] = i;
        }
    }
}

private static boolean isPrime(int n){
    int sqrt = (int) Math.ceil(Math.sqrt(n));
    if(n % 2 == 0) return false;
    for(int i = 3; i < sqrt; i += 2){
        if(n % i == 0) return false;
    }
    return true;
}

My question is, does this hold true (obviously since the Goldbachs conjecture hasnt been proven yet I am not wondering about a proof, just if this is true for a large data set) or did I write my program wrong?