Project Euler problem 60
Both methods are enumeration, but the details are slightly different.
Suppose: The relationship described in the question is called relationship P, and the two prime numbers satisfy the relationship p. We have generated a prime number table. It stores many prime numbers from small to large.
First thought:
1. We generate a linked list for each prime number. The linked list stores the prime number that satisfies the relationship P with the Header element from small to large.
2 any two linked lists, as long as the non-Header element has a projection element, are a triple that satisfies the relationship p.
3. Based on a triple, we constantly expand and find a quintuple. Of course, the quintuple may be a solution, or not.
Find the other quintuple that satisfies the relationship, and then select a minimum.
The second approach:
The one-dimensional prime number table is extended into a two-dimensional table that satisfies the relationship p. As long as two prime numbers I and j meet the relationship P, map [I] [J] = 1; (here we can use ing to save space, or we can skip this optimization)
Then the problem is converted to finding a quintuple that meets the requirements of map [I] [J] = 1. Use enumeration.
Problem revelation: two ways to expand one dimension to two dimensions.
Answer: 26033