Exam questions over the years-the number of questions you cannot buy, and the number of questions over the years

Source: Internet
Author: User

Exam questions over the years-the number of questions you cannot buy, and the number of questions over the years
Problem description

James opened a candy store. He was ingenious: He made water fructose into four one package and seven one package. Candy cannot be sold in a package.

When a child comes to buy sugar, he uses these two packages for combination. Of course, the quantity of some candy cannot be combined, for example, to buy 10 sugar.

You can test it on a computer. In this case, the maximum number of packages that cannot be purchased is 17. Any number greater than 17 can be combined with 4 and 7.

The requirement for this question is to find the maximum number that cannot be combined when the number of two packages is known.

Input Format

Two positive integers, indicating the number of sugar in each package (no more than 1000)

Output Format

A positive integer that indicates the maximum number of sugar that cannot be bought

Sample input 14 7 sample output 117 sample input 23 5 sample output 27
// The number that you cannot buy after understanding it. // The input a and B can be multiplied by a number that cannot exceed n (we define a relatively large number) // then mark the number you can buy with an array as 1. You cannot buy it. The default value is 0. // The final traversal array. If there is a continuous a, you can buy it, minus the one closest to. the value of // 0 is the maximum number that cannot be purchased. a must ensure that it is a small input number./* # include <iostream> # include <algorithm> # include <cstring> # include <cmath> using namespace std; long n = 100000; int d, x; int cha (int a []) {int sum = 0; for (int I = 0; I <n; I ++) {if (a [I] = 1) {sum ++; if (sum> = x) return I-x; // if you can buy x in a row, subtract x from the number.} else {sum = 0 ;}} return-1 ;}void f (int a, int B) {int c [n]; for (int I = 0; I <n/a; I ++) // In order to ensure that the next multiplication a B does not overflow for (int j = 0; j <(n-I * a)/B; j ++) {if (I * a + B * j <n) c [I * a + j * B] = 1; // indicates that the candy} cout <cha (c);} int main () {cin> x> d; if (x> d) can be found) {int t = x; x = d; d = t;} f (x, d );}
Implementation Code

 

Related Article

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.