Although it is a deep search, its ownCodeAlways wa...
I read some code online, basically the same way.
Worship ing...
/*************************************** **************************************** # Author: neo Fung # Email: neosfung@gmail.com # Last modified: # filename: zoj1003 crashing balloon. CPP # description: **************************************** **************************************/# ifdef _ msc_ver # define debug # DEFINE _ crt_secure_no_deprecate # endif # include <fstream> # include <stdio. h> # Include <iostream> # include <string. h> # include <string> # include <limits. h> # include <algorithm> # include <math. h> # include <numeric> # include <functional> # include <ctype. h> # define Max 101 using namespace STD; int flag1, flag2; void DFS (int x, int y, int N) {If (y = 1) {flag2 = 1; if (x = 1) flag1 = 1; // The first decomposition is smaller than the decimal number, so the larger number is decomposed (that is, flag1 is set to 1) if (n> 100 | flag1 = 1 & flag2 = 1) return; // recursive Exit: N exceeds 100, or both numbers are decomposed if (x % N = 0) DFS (x/N, Y, n + 1); // large numbers use the factor n if (Y % N = 0) DFS (X, y/n, n + 1); // use the factor n DFS (X, Y, n + 1) for a small number; // neither use the factor n} int main (void) {# ifdef debug freopen (".. /stdin.txt "," r ", stdin); freopen (".. /stdout.txt "," W ", stdout); # endif int A, B, T; while (~ Scanf ("% d", & A, & B) {if (a <B) {T = A; A = B; B = T ;} // make sure A> B flag1 = flag2 = 0; DFS (A, B, 2); // start searching from 2 // printf ("% d/N ", flag1, flag2); If (flag2 &&! Flag1) printf ("% d \ n", B); // only when the challenge succeeds, that is, the decimal part is successfully decomposed, else printf ("% d \ n", a);} return 0 ;}