-3

So the riddle is:

John has written down k sequential odd numbers: n{1}, n{2}, ..., n{k-1}, n{k} (where n{2} = n{1} + 2 and so on). We know that:

  • The sum of the first four numbers is a fourth power of some prime number (so n{1} + n{2} + n{3} + n{4} = p{1} where p{1}^4 is a prime number.
  • The sum of the last five numbers is a fourth power of some prime number (so n{k} + n{k-1} + n{k-2} + n{k-3} + n{k-4}= p{2}^4 where p{1} is a prime number.

The question is - how many numbers have been written down (k=?).

Below is my attempt to solve it in Java:

import java.math.BigInteger;
import java.util.Set;

//precalculate prime numbers
public class PrimeSieve {


 public static boolean[] calculateIntegers(int N) { 


    // initially assume all integers are prime
    boolean[] isPrime = new boolean[N + 1];
    for (int i = 2; i <= N; i++) {
        isPrime[i] = true;
    }

    // mark non-primes <= N using Sieve of Eratosthenes
    for (int i = 2; i*i <= N; i++) {

        // if i is prime, then mark multiples of i as nonprime
        // suffices to consider mutiples i, i+1, ..., N/i
        if (isPrime[i]) {
            for (int j = i; i*j <= N; j++) {
                isPrime[i*j] = false;
            }
        }
    }

    return isPrime;
  }
}

The solving class:

public class Solver {
    static boolean[] isPrime = PrimeSieve.calculateIntegers(100000);

    public static void main(String[] args) {

        int minNumberCount = 5;
        int maxNumberCount = 2000;
        int startInt = 2;
        int endInt = 1000000;

        for (int numberCount = minNumberCount; numberCount < maxNumberCount+1; numberCount++) {
            System.out.println("Analyzing for " + numberCount + " numbers");

            int[] numbers = new int[numberCount];

            //loop through number sets
            for (int firstNum = startInt; firstNum < endInt; firstNum+=2) {

               //populate numbers array
                for(int j=0; j<numberCount; j++){
                    numbers[j] = firstNum + j*2;
                }

                long bottomSum=0;
                long topSum=0;

                //calculate bottom sum
                for(int iter=0; iter<4; iter++){
                    bottomSum+=numbers[iter];
                }

                //calculate top sum
                for(int iter=numberCount-1; iter>numberCount-6; iter--){
                    topSum+=numbers[iter];
                }

                //check if the sums match the sulution criteria
                if(checkPrime(quadRoot(bottomSum)) && checkPrime(quadRoot(topSum))){
                    System.out.println("SOLUTION!");

                    for (int i = 0; i < numbers.length; i++) {
                        System.out.print(numbers[i] + " ");
                    }
                    System.exit(0);
                }
            }       
        }
    }

    private static boolean checkPrime(int i){
        return isPrime[i];
    }

    private static boolean checkPrime(double i){
        return ((i % 1) == 0) && checkPrime((int) i);
    }

    private static double quadRoot(long n){
        return Math.sqrt(Math.sqrt(n));
    }

 }

Using this algorithm with the assumed parameters (max k=2000, max n{1}=100000) - I've found no solution. My question is: are the parameter assumptions wrong (no solution in this range), or do I have some algorithmic/numeric error and that is the reason I've found no solution?

EDIT: sorry - my mistake - it should be ODD instead of EVEN.

4

3 回答 3

4

直接解决这个问题比编写程序更容易。

第一个和是偶数,所以它必须是 16(因为 2 是唯一的偶数素数)。因此,前四个数字是 1、3、5、7。

五个连续奇数之和是中间数的 5 倍,因此必须能被 5 整除。由于它是素数的四次方,它必须是 625,因此最后五个数字是 121,123,125,127,129

现在很容易确定 k=65

于 2013-09-19T08:26:19.503 回答
0

如果只有偶数,则它们的总和是偶数。如果我理解正确,您的总和必须是素数的四次方的结果。考虑到总和是偶数,满足条件的唯一数是 16 (2*2*2*2),其中 2 是质数,所以 4 个偶数的总和必须是 16。现在,如果你'确定有一个序列,然后通过将序列中的第一个和最后一个数字相加,然后将结果与序列中的元素数相乘,并将相乘的结果除以 2 来计算总和。例如, 2+4+6+8=(2+8)*4/2=10*4/2=20。同样,对于您的示例, n{1}+n{2}+...+n{k}=(n{1}+n{k})*k/2 在旁注中,您的最小总和为 4偶数(20),我使用的例子,已经高于你唯一的素数(16)的4次方,所以是的,

我希望这有点道理

于 2013-09-19T08:24:23.727 回答
0

正如评论中所说,您的谜语没有解决方案。

假设有一个解决方案,那么n1 + n2 + n3 + n4 == p1^4。我们知道 n1,n2,n3,n4 根据谜语的定义是偶数,因此作为偶数之和,n1 + n2 + n3 + n4也是偶数。这使我们得出一个事实,即p1^4是平的。我们知道两个奇数相乘只能得到一个奇数,因此p1^4 = p1 * p1 * p1 * p1意味着 p1 必须是偶数。但是,p1 是素数。唯一也是偶数的素数是 2。很容易看出,没有四个连续的偶数总和为 16,因此 p1 不是素数。这与 p1 是素数的假设相矛盾,因此没有解决方案。

于 2013-09-19T08:22:48.490 回答