XiaoKai has two kinds of coins whose values are coprime integers. For each kind, he can use as many as needed. It's been proven that if the price of something is large enough, XiaoKai can always pay the exact amount just by using these two kinds of coins.
If a and b are the two coprime integers, what is the maximum price of something he can't pay exactly ?
This problem is from NOIP2017 , aka National Olympiad in Informatics in Provinces, a programming contest held in China.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
I solved this problem with respect to symmetry: Since we don't know whether a or b is the larger of the two integers, the solution must stay the same if we exchange them. So any solution with different signs before a and b is not possible. And since a × b + a + b is a price, which can be paid, the only solution left is a × b − a − b , which is the right one.
Obviously this only works if possibilities for solutions are given.
In the ones where it's a x b - a + b and a x b + a - b, is the only instance where it can be paid when a or b is 1? (since 1 is co prime with everything)
Take a , its multiples cover numbers of form a × k , from a to infinity ( k ∈ N ). If we introduce shifts of amount s ∈ { 1 , 2 , … , a − 1 } , then we can cover numbers of form a × k + s , from a + s to infinity. The shift is provided by b , but it would not take effect from the beginning. in order to find the first number of form a × k + s we need to solve b x ≡ s ( m o d a ) for x . Having x , b x would be the first number of the form a × k + s . There would be a solution, as a and b are coprimes. Also, for each s ∈ { 1 , 2 , … , a − 1 } there is a unique solution x ∈ { 1 , 2 , … , a − 1 } . Then we find the maximum of b x , which is b ( a − 1 ) . the number b ( a − 1 ) is the starting point of covering that is given by a specific shift. so, the previous number of the similar form, is the largest that has not been covered. that would be b ( a − 1 ) − a = b a − b − a
Problem Loading...
Note Loading...
Set Loading...
If a price P can be paid using such coins, this is equivalent to saying there exist non-negative integers m and n such that P = m a + n b . The last three options have such expressions:
By process of elimination, the solution is a b − a − b .
A more direct (and perhaps more satisfying) proof, without taking advantage of multiple choice: Let P be the largest such price. Then P + a = s a + t b for some s , t ≥ 0 . That means P = ( s − 1 ) a + t b . If s > 0 , then this gives P as a sum of positive integer multiples of a and b , which contradicts our construction of P . Therefore s = 0 and P + a = t b . A symmetrical argument shows that P + b = k a , some k > 0 . Then
P = t b − a = k a − b
⟹ k a + a = t b + b
⟹ ( k + 1 ) a = ( t + 1 ) b
⟹ a ∣ ( t + 1 ) b and b ∣ ( k + 1 ) a
Since a and b are relatively prime, we must have a ∣ ( t + 1 ) and b ∣ ( k + 1 ) , i.e. there are positive integers u and v such that t + 1 = a u and k + 1 = b v . Then ( b v ) a = ( k + 1 ) a = ( t + 1 ) b = ( a u ) b , meaning u = v . Thus a b u = k a + a = t b + b ⟹ a b u − a − b = k a − b = t b − a = P .
Suppose x and y are non-negative integers such that u = x + y . Then
P = a b ( x + y ) − a − b
= a b x + a b y − a − b
= ( b x − 1 ) a + ( a y − 1 ) b
If b x − 1 > 0 and a y − 1 > 0 , then we have an expression for P as a sum of non-negative integer multiples of a and b , which is impossible. Therefore either x = 0 or y = 0 , meaning u = 1 and P = a b − a − b . □