Think of a discount question: One dollar a bottle of soda, two empty bottles can change a bottle of soda, ask 20 yuan can drink how many bottles of soda?

Source: Internet
Author: User

1, first summed up the algorithm:

Whether you buy a bottle of a bottle or a one-time buy, the result is the same.

A, first buy 20 bottles

B, 20 empty bottles for 10 bottles

C, 10 empty bottles for 5 bottles

D, 5 empty bottles for 2 bottles left an empty bottle

E, 2 empty bottles for 1 bottles

F, 2 empty bottles, one more bottle.


2, the implementation of the program:

int max =;
int sum = max;
int result = max;
int mode = 0;
int base_number = 2;
while (Result! = (base_number-1)) {
     mode = result% Base_number;
     Result/= Base_number;
     sum + = result;
     result + = mode;
}


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.