The focus of the question in question solution is to clearly analyze the rules for winning or losing.
Use two bool variables to indicate whether the two are telling the truth, DFS. If B is telling the truth and A is not telling the truth, B wins, and the rest are a wins.
# Include <cstdio> # include <algorithm> # include <iostream> using namespace STD; int n, m, F1, F2; void DFS (int A, int B, int num) {if (a = 1 & B = 1) // One solution is that both parties tell the truth. Only when both are true can a be confirmed to be honest. {F1 = F2 = 1; return;} If (B = 1) f2 = 1; // B tell the truth while (Num> 1) {if (a % num = 0) DFS (A/num, B, num-1 ); if (B % num = 0) DFS (a, B/num, num-1); num -- ;}} int main () {While (~ Scanf ("% d", & N, & M) {If (M> N) Swap (m, n); F1 = F2 = 0; DFS (n, m, 100); If (! F1 & F2) printf ("% d \ n", m); else printf ("% d \ n", n);} return 0 ;}
Zoj1003 crashing balloon