Smart question about numbers-sum and product of two numbers

Source: Internet
Author: User

Question:

Two 1-2 known ~ The number between 30. A knows the sum of two numbers, and B knows the product of two numbers.
A asked B: "Do you know which two numbers are there? "B said:" I don't know ";
B asked a: "Do you know which two numbers are there? "Jia said:" I don't know ";
So, B said, "Then I know ";
Then Jia also said, "Then I know ";
What are the two numbers?

Answer:

Implicit condition: If B does not know the answer, the product of the two numbers is not a prime number. When a says "I don't know the answer", B immediately knows the answer, indicating that B can use this information to exclude some options, leaving the only option. In turn, after B gets the answer and tells a, a can also use this information to exclude some options, leaving the only option.

For example:

Assume that the two numbers are X and Y. A = x + y; B = x * Y.

From the perspective of Party B, assume that B is 6, which can be a combination of () and. At this time, B hesitated between the two combinations and told B that he did not know the answer.

Suppose the answer is (), then a = 7. In this case, the options on the device A should be (), (), and ). At this time, Jia does not know the answer, so () is a candidate answer. Suppose the answer is (2, 3), then a = 5. At this time, the options in the hands of Jia are () and (), so Jia cannot know the answer. At this time, (2, 3) also became a candidate answer. In this case, there are two candidate answers, so B cannot come to the end. This is in conflict with the question settings. These combinations can be ruled out at one time.

 

 

Assume that B = 4.

From the perspective of Party B, the options of Party B are () and ).

Assume the answer is ). Then a = 5. The analysis is as follows. B uses () as a candidate answer. Assume that the answer is (2, 2), then a = 4. In this case, the options on the device a are (1, 3) AND (2, 2 ). Because the product of () is a prime number, it is excluded. Then, when Party B tells Party A that he does not know the answer, Party A should be able to know the answer. In fact, Party A does not know the answer. Therefore, (2, 2) is impossible. Finally, B had only one candidate answer, so he gave out the answer. In turn, Jia can also provide answers based on this information. Therefore, (1, 4) meets the question.

void BrainTester::ABOf1_30() {multimap<int, pair<int, int> > mid_result;for (int x = 1; x <= 30; ++x) {for (int y = x; y <= 30; ++y) {if (!this->isPrime(x * y)) {mid_result.insert(make_pair(x * y, make_pair(x, y)));}}}set<int> key_set;multimap<int, pair<int, int> >::iterator it;for (it = mid_result.begin(); it != mid_result.end(); ++it) {key_set.insert(it->first);}set<int>::iterator it_set;for (it_set = key_set.begin(); it_set != key_set.end(); ++it_set) {if (mid_result.count(*it_set) <= 1) {while ((it = mid_result.find(*it_set)) != mid_result.end())mid_result.erase(it);}}key_set.clear();//reset key_setfor (it = mid_result.begin(); it != mid_result.end(); ++it) {key_set.insert(it->first);}multimap<int, pair<int, int> >::iterator beg;multimap<int, pair<int, int> >::iterator en;bool flag = false;multimap<int, pair<int, int> > result;for (it_set = key_set.begin(); it_set != key_set.end(); ++it_set) {beg = mid_result.equal_range(*it_set).first;en = mid_result.equal_range(*it_set).second;for (; beg != en; ++beg) {int x = beg->second.first;int y = beg->second.second;int sum = x + y;if (sum > 3) {int half = sum / 2;flag = false;for (int i = 1; i <= half; ++i) {if (mid_result.find(i * (sum - i)) != mid_result.end()) {if (flag) {result.insert(make_pair(x * y, make_pair(x, y)));break;} else {flag = true;}}}}}}key_set.clear();for (it = result.begin(); it != result.end(); ++it) {key_set.insert(it->first);}for (it_set = key_set.begin(); it_set != key_set.end(); ++it_set) {if (result.count(*it_set) != 1) {while ((it = result.find(*it_set)) != result.end())result.erase(it);}}for (it = result.begin(); it != result.end(); ++it) {cout << it->first << " (" << it->second.first << ","<< it->second.second << ")" << endl;}}

  

 

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.