The nature of UVA 571 primes

Source: Internet
Author: User

Given two cups, the capacity is divided into CA,CB, so that we can pour it with these two bottles to get a bottle of water containing n

And the data to be guaranteed Cb > N, and CA,CB coprime

Then we can definitely get n water in the CB-size cup.

The least common multiple of CA and Cb is CA*CB

We set up RI <CB

So RI * Ca% Cb! = 0, and the remainder obtained are different

Because if there are two of the remainder of the same, we may as well set RI * CA% cb = RJ * CA% CB (RJ>RI)

So then ca* (Rj-ri)%CB =0 and Ca and Cb least common multiple is CA*CB contradiction

So the remainder cannot be the same, and the remainder is 1->cb-1, so we can definitely get the remainder n

1#include <stdio.h>2 intMain () {3     intA, B, a, b, aid;4      while(SCANF ("%d%d%d", &a, &b, &aid) = =3) {5A = b =0;6          while(1) {7             if(b = =aid) {8printf"success\n");9                  Break;Ten             } One             Else if(b = =B) { Aprintf"Empty b\n"); -b =0; -             } the             Else if(A = =0) { -printf"Fill a\n"); -A =A; -             } +             Else { -printf"pour A b\n"); +                 intc = min (B-B, a); AB + =C; atA-=C; -             } -         } -     } -     return 0; -}
View Code

The nature of UVA 571 primes

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.