ZOJ-1003-Crashing Balloon(검색)


Crashing Balloon
Time Limit: 1 Second      Memory Limit: 32768 KB
On every June 1st, the Children's Day, there will be a game named "crashing balloon"on TV.   The rule is very simple.  On the ground there are 100 labeled balloons, with the numbers 1 to 100.  After the referee shouts "Let's go!"the two players, who each starts with a score of  "1", race to crash the balloons by their feet and, at the same time, multiply their scores by the numbers written on the balloons they crash.  After a minute, the little audiences are allowed to take the remaining balloons away, and each contestant reports his/her score, the product of the numbers on the balloons he/she's crashed.  The unofficial winner is the player who announced the highest score.
Inevitably, though, disputes arise, and so the official winner is not determined until the disputes are resolved.  The player who claims the lower score is entitled to challenge his/her opponent's score.  The player with the lower score is presumed to have told the truth, because if he/she were to lie about his/her score, he/she would surely come up with a bigger better lie.  The challenge is upheld if the player with the higher score has a score that cannot be achieved with balloons not crashed by the challenging player.  So, if the challenge is successful, the player claiming the lower score wins.
So, for example, if one player claims 343 points and the other claims 49, then clearly the first player is lying; the only way to score 343 is by crashing balloons labeled 7 and 49, and the only way to score 49 is by crashing a balloon labeled 49.  Since each of two scores requires crashing the balloon labeled 49, the one claiming 343 points is presumed to be lying.
On the other hand, if one player claims 162 points and the other claims 81, it is possible for both to be telling the truth (e.g. one crashes balloons 2, 3 and 27, while the other crashes balloon 81), so the challenge would not be upheld.
By the way, if the challenger made a mistake on calculating his/her score, then the challenge would not be upheld. For example, if one player claims 10001 points and the other claims 10003, then clearly none of them are telling the truth. In this case, the challenge would not be upheld.
Unfortunately, anyone who is willing to referee a game of crashing balloon is likely to get over-excited in the hot atmosphere that he/she could not reasonably be expected to perform the intricate calculations that refereeing requires.  Hence the need for you, sober programmer, to provide a software solution.

Input


Pairs of unequal, positive numbers, with each pair on a single line, that are claimed scores from a game of crashing balloon.

Output


Numbers, one to a line, that are the winning scores, assuming that the player with the lower score always challenges the outcome.

Sample Input

343 49
3599 610
62 36


Sample Output

49
610
62

24와 12의 모든 인자가 2, 3, 4, 6, 8, 12인 것을 찾아내고 이 인자 중에서 검색해서 제시된 두 수를 다시 곱할 수 있는지 확인하는 것이다
마지막 결과 판단의 번거로움은 제목이 작은 자에게 도전을 요구한다. 만약에 큰 자가 거짓말을 증명당하면 작은 자가 이기고 큰 자가 성립할 수 있다면 큰 자가 이기고 작은 자가 자신의 결과에 대한 계산이 틀리면 작은 자가 성립할 수 없다. 만약에 인자에 100보다 큰 질수가 포함되면 도전은 열리지 않고 큰 자가 이긴다.
이런 논리가 있어요.
if(min ok)
{
    if(max ok)
        cout<    else cout<}
else cout<그래서 먼저 인자 중에서 비교적 작은 수를 맞추고, 만약 성공한다면, 다시 비교적 큰 수를 맞추어라
#include using namespace std; int factor[100]; int used[101]; int a,b,j,mmax,mmin,pa; bool flag; bool dfs(int i, intcur, intd) {if(i=j) {if(!flag & &cur==mmin)/flag는 검색 조합의 수를 제어하는 데 사용됩니다 {pa=1;flag=true;if(dfs(0,1,mmax)))return true;flag=false;}else if(flag&&cur==mmax) { pa=2; return true; } } else { int mul=factor[i]*cur; if(mul<=d&&used[factor[i]]==0) { used[factor[i]]=1; if(dfs(i+1,mul,d)) return true; used[factor[i]]=0; } if(dfs(i+1,cur,d))return true; } return false; } int main() { int a,b; while(cin>>a>>b) { j=0;pa=0;flag=false; if(a>b) { mmin=b;mmax=a; } else { mmin=a;mmax=b; }//만약 두 수가 모두 100 이내라면 직접 결과를 내if(a<=100&b<=100&&a!=b)cout 

좋은 웹페이지 즐겨찾기