[Blue Bridge Cup] can't buy the number

Source: Internet
Author: User

[Blue Bridge Cup] can't buy the number

Peak memory consumption < 64M CPU consumption < 3000ms

"Title Description-Problem Description"

Xiao Ming opened a candy shop. His ingenuity: to pack the fruit candy into 4 packs and 7 packs of two. Sweets cannot be sold by unpacking.

When the children came to buy the sugar, he used the two kinds of packaging to combine. Of course, some of the number of sweets can not be combined, such as to buy 10 sugar.

You can test it with a computer, in which case the maximum quantity that cannot be bought is 17. Any number greater than 17 can be combined with 4 and 7.

The requirement of the subject is to find the maximum number of characters that cannot be combined when the quantity of two packages is known.

"Input-Input"

"Output-outputs"

Two positive integers representing the number of sugars in each package (no more than 1000)

A positive integer representing the maximum number of sugars that cannot be bought

No need to consider the case of no solution

"Input sample 1-sample input 1"

"Output sample 1-sample outputs 1"

6 U 17

"Input sample 2-sample input 2"

"Output sample 2-sample outputs 2"

3 5 7

Exercises

Violent solution, upper limit visual is a*b. Probably can.

Or use the formula A*b-a-b (number theory ...). Indefinite equation, whether you understand it or not, I don't understand it anyway. _?)

Other forms of proof:

For 4 7

  

4 and 7, a large period of 7, a small period of 4, the current layer can be filled with the next layer of the corresponding lattice can also be filled.

The start position is 0/4, then the period difference between 4 and 7

The fill is completed after 7*4, and the last populated number is 7 * 4–4.

The largest unfilled number is on the previous level, which is 7*4–4–7.

Replace the letter to get the formula A*b–a–b.

"Code C + +"

1#include <cstdio>2 #defineMX 10000053 intDATA[MX];4 intMain () {5     intI, J, A, B;6scanf"%d%d", &a, &b);7Data[a] = data[b] =1;8      for(i = a + b/2; I <= a*b; ++i) {9         if(Data[i-a]) + +Data[i];Ten         if(Data[i-b]) + +Data[i]; One     } A      for(i = a*b; data[i];--i); -printf"%d", i); -     return 0; the}

"Measurable Address" http://acmore.cc/problem.php?id=1601

[Blue Bridge Cup] can't buy the number

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.