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