The fourth Blue Bridge cup question-Sloppy formula, the fourth Blue Bridge

Source: Internet
Author: User

The fourth Blue Bridge cup question-Sloppy formula, the fourth Blue Bridge

 

Enumeration

James is an acute child. When he was in elementary school, he often copied the questions that the teacher wrote on the blackboard wrong.

On one occasion, the instructor gave the Question 36x495 =?

He copied: 396x45 =?

But the results were dramatic. His answer was correct!

Because 36*495 = 396*45 = 17820.

There may be many coincidences like this, such as 27*594 = 297*54.

Assume that a B c d e represents 1 ~ 9 different 5 numbers (note that they are different numbers and do not contain 0 ).

Which of the following formula can be satisfied: AB * cde = adb * ce?

Please take advantage of the computer to find all possibilities and answer the different types of formulas.

The formula that satisfies the multiplication exchange law is counted as different types, so the answer must be an even number.

 

#include<iostream>using namespace std;int main(){    int a,b,c,d,e,num=0;    for(a=1;a<10;a++)    {        for(b=1;b<10;b++)        {            if(a==b)                continue;            for(c=1;c<10;c++)            {                if(a==c||b==c)                    continue;                for(d=1;d<10;d++)                {                    if(a==d||b==d||c==d)                        continue;                    for(e=1;e<10;e++)                    {                        if(a==e||b==e||c==e||d==e)                            continue;                        if(((a*10+b)*(c*100+d*10+e))==((a*100+d*10+b)*(c*10+e)))                            num++;                    }                }            }        }    }    cout<<num<<endl;    return 0;}

 

Because there are a total of five numbers, it is better to have a five-weight loop, instead of a nine-weight loop.

Related Article

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.