Solve a math problem with PHP "There are many experts to solve, look forward to a better algorithm for the emergence of"

Source: Internet
Author: User
Http://www.111cn.net/html/00/54500_itemid_29653.html

A six-digit number, when used separately by the 2,3,4,5,6, the resulting five product is a six-digit number, and the five numbers are made up of six digits, but the order is changed!
Ask the Master to help solve!




---------------

looks like everyone's tacitly a phenomenon.
Http://www.111cn.net/viewthread.php?tid=54377&page=5

A previous hypothesis seems to be that everyone does not consider the existence of the algorithm when this situation may be if there is any argument that this assumption does not set up or the landlord's title itself by default does not consider this assumption please the heroes to explain

If there is no argument or the topic is not clearly stated that does not consider this hypothetical algorithm design is also the problem of invalid algorithm


------------------------



Two algorithms are written:
The first is to determine whether the sum of each bit of the multiplication is equal, but not in a very efficient way.
The second algorithm is a new way of thinking, with the character reverse direction validation, because the forward will have a part of the high level of unnecessary operations. The code is concise and efficient, with code:

The first algorithm that determines the sum of the various digits:


===========================================================

The second algorithm, the character of the reverse direction query:



The first algorithm needs 440ms on my Pe2140@2.66ghz, and the second one only needs 180ms.




---------------------------------



I've mentioned this question before, http://www.111cn.net/bbs/thread-54377-2-1.html.

There is one way to solve this problem:
Get every bit, one bit out.
If two digits are the same, two are deleted or changed at the same time.
Like what:
' 123451 ' and ' 123456 '
If you delete or change a bit, the rest will not wait.





----------------------------------



for ($i = 100000; $i < 166667; $i + +)//number range
{
....
For ($ii =2 $ii <7; $ii + +)//2-6 Multiples
{
.....
For ($j =0 $j <6; $j + +)//number
{
if ( strpos $i $i $j

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.