Computer solution on a mathematical question.

xiaoxiao2021-03-05  23

topic:

A, B, C three people and two 2 to 99 integers, C knows these two numbers, he tells the two numbers and tells A, then tell C, then ask A, B: " What is the two numbers? "A said:" I don't know these two numbers, but I can affirm B, I don't know! "I listened to A, I said:" I didn't know, but listened to A. Just know how much it is, "said that" "I also know how much." What is the number of these two? "

I have three groups of answers: 4, 13; 4,61; 16,73

First, because a affirm b does not know, we assume that a known to M, then for equation x y = m, in the integer solution between 2 to 99, there is at least one of the compliance.

Because B listened to a, I will know, set x * y = n, set the integer solution between its 2 to 99 to X1, Y1; X2, Y2; ... xi, yi; for any set of Xi, Yi, finding the sum, and then push once according to the thought of A. If there is only one set of solutions to satisfying a condition, then B can determine that these two numbers are positive solution.

Simultaneously listening to B, then the idea of ​​all the solutions to B. If there is only one set of solutions, then they are correct.

The procedures I wrote are as follows:

#include

#define max 99 # Define min 2 # define true 1 # define false 0

INT MUTEX = 0; // Mutually exclusive semaphore INT FINDOUTFLAG = 0; // When you find a satisfaction, you will set the FindoutFlag 1. INT A = 0, b = 0; // Since the two numbers

// my functionint twokey (int CHECKA (INT M); // a Depending on his condition. INT CHECKB (INT M); // B can be judged according to his conditions. Int isprimenumber (int m); // is not a number of prime

INT TWOKEY (INT M) {IF (m-3 <= (m 1) / 2) {Return False;} Return True;

INT CHECKA (INT M) {INT FLAG = 0; for (int i = min; i <= (m 1) / 2; i ) {IF (Isprimenumber (MI) && isprimenumber (i)) {FLAG = 2; Return false;} if (i == (m 1) / 2 && mutex == 0) {FindOutflag = 0; for (int J = 2; j <= (m 1) / 2; J ) {IF ( Checkb ((mj) * j) == true) {FindOutflag ;} if (Findoutflag> 1) {Break;} if (j == (m 1) / 2 && findoutflag == 1) {IF (a B <= 101) Printf ("% D,% D / N", A, B);}}} f (i == (m 1) / 2) {return true;}}}} int Checkb (int N) {Int getNumber [50] [2]; int group = 0; int ok = 0, Number;

For (int i = min; i <= n / i; i ) {if ((N% i) == 0) {getNumber [group] [0] = i; getNumber [group] [1] = n / i ; Group ;}} mutex = 1; for (int J = group - 1; j> = 0; j -) {if (CHECKA (GetNumber [J] [0] GetNumber [J])! = True) {} else {ok ; number = j;}} if (ok == 1) {a = getNumber [number] [0]; b = getNumber [Number] [1]; mutex = 0; ok--; Return True;} mutex = 0; return false;

}

INT ISPRIMENUMBER (INT M) {for (INT i = min; i <= (m 1) / 2; i ) {IF ((M% I) == 0) {Return False;}} return true;

Void main () {for (INT i = min; i <= 2 * max-1; i ) {if (Twokey (i) == true) Checka (i);}}

转载请注明原文地址:https://www.9cbs.com/read-31819.html

New Post(0)