Project Euler problem 60

Source: Internet
Author: User

 

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.