Zoj1003:crashing Balloon

Source: Internet
Author: User

Time Limit:2 Seconds Memory limit:65536 KB

On every June 1st, the children's Day, there'll be a game named "Crashing Balloon" on TV.  The rule is very simple.  On the ground there is labeled balloons, with the numbers 1 to 100. After the referee shouts "let's go!" the "the" the "the" and "the" the "the" the "the" starts with a score of "1" and 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 is 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 announced the highest score.
Inevitably, though, disputes arise, and so the official winner was not determined until the disputes was resolved.  The player who claims the lower score are entitled to challenge His\her opponent ' s score. The player with the lower score are presumed to having 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 have a score that cannot being 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, then clearly the first player is lying; The only-to-score 343 is by crashing balloons labeled 7 and, and the-only-to-score is by crashing a balloon  Labeled 49. Since each of the scores requires crashing the balloon labeled, the one claiming 343 points are presumed to be lying.

On the other hand, if one player claims 162 points and the other claims Bayi, it's possible for both to be telling the Trut H (e.g. one crashes balloons 2, 3 and, while the other crashes balloon Bayi), so the challenge would isn't be upheld.

By the the-the-the-challenger made a mistake on calculating his/her score and then the challenge would isn't be upheld. For example, if one player claims 10001 points and the other claims 10003, then clearly none of them is telling the truth . The challenge would not being upheld.

Unfortunately, anyone who are willing to referee a game of crashing balloon are likely to get over-excited in the hot ATMOSP  Here's he\she could not reasonably is expected to perform the intricate calculations that refereeing requires. Hence the need for your, sober programmer, to provide a software solution.

Input

Pairs of unequal, positive numbers, with all pair on a single line, that is claimed scores from a game of crashing Ballo On.

Output

Numbers, one to a line, that is the winning scores, assuming that the player with the lower score always challenges the O Utcome.

Sample Input

343 493599 61062 36

Sample Output

4961062

The difficulty with this problem is that two players may have several different decomposition schemes, so long as any one of the decomposition schemes does not conflict, the challenger wins. The reference code is as follows:

#include <stdio.h>bool atrue, btrue; int judge (int m, int n, int p) {     if (atrue) return 0;    if (m = = 1 && n = = 1)            {        atrue = true; return 0;        }    if (n = = 1) Btrue = true;       while (P > 1)    {        if (m%p = = 0) judge (m/p, N, p-1);        if (n%p = = 0) judge (M, n/p, p-1);        p--;    }    return 0;}   int main () {    int A, b;     while (scanf ("%d%d", &a, &b)!=eof)    {        if (a < b)                                    {int temp = A; a = b; b = temp;}            Atrue = false; Btrue = false;           Judge (A, B, +);        if (!atrue && btrue)                           printf ("%d\n", b);                    else            printf ("%d\n", a);                }    return 0;}

Other people's ideas, the code is as follows:


#include <stdio.h>
int Flag1, flag2;//represents N, whether M has been successfully decomposed by void Dfs (int n, int m, int fac = +) {if (FLAG1)//If n, M can be decomposed and the factor is different return;if (n = = 1 && Amp m = = 1) {//n, M is decomposed Flag1 = 1;flag2 = 1;return;} if (m = = 1) {//m decomposition Flag2 = 1;} if (FAC < 2) return;if (n% FAC = = 0)//essence, the same factor is not decomposed at the same time N, m, difficulty resolving Dfs (N/FAC, M, fac-1); if (m% FAC = = 0) dfs (n, M/FAC, FAC-1);d FS (n, M, fac-1);} int main () {int n, m;while (~scanf ("%d%d", &n, &m)) {if (M > N) {//interchange m, nn = m ^ n;m = m ^ n;n = m ^ n;} Flag1 = 0;flag2 = 0;dfs (n, m), if (Flag1 | |!flag2)//If n successfully decomposes goods m cannot successfully decompose printf ("%d\n", N); elseprintf ("%d\n", m);} return 0;}


about algorithmic art and practice more discussion and communication, please pay attention to this blog and Sina Weibo songzi_tea.




Zoj1003:crashing Balloon

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.