The number that can't be bought

Source: Internet
Author: User

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 format

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

Output format

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

Sample Input 14 7
Sample output 117 Sample input 23 5
Sample Output 2

7

Number theory: Two coprime, the largest integer that cannot be combined is n (m-1)-m, number of integers that cannot be combined (n-1) * (m-1)/2

#include <iostream> #include <cstdio>using namespace Std;int main () {    int n,m;    while (scanf ("%d%d", &n,&m)!=eof) {        printf ("%d\n", n*m-n-m);    }    return 0;}


The number that can't be bought

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.