- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find maximum how many water bottles we can drink in Python

Suppose there are n number of full water bottles, we can exchange m empty water bottles for only one full water bottle. Now drinking a full water bottle makes it an empty bottle. We have to find the maximum number of water bottles we can drink.

So, if the input is like n = 9, m = 3, then the output will be 13 because initially we have 9 bottles, so after drinking all bottles, we can get 9/3 = 3 full bottles, after drinking them all we have three empty bottles and using them we can buy one and drink it, so we completed 9 + 3 + 1 = 13 bottles.

To solve this, we will follow these steps −

x:= n, s:= 0, k:= 0

while x >= m, do

k:= x mod m

x:= quotient of x / m

s:= s + x

x:= x + k

return n + s

## Example (Python)

Let us see the following implementation to get better understanding −

def solve(n, m): x=n s=0 k=0 while x >= m: k=x % m x=x // m s=s + x x=x + k return n + s n = 9 m = 3 print(solve(n, m))

## Input

9, 3

## Output

13

- Related Questions & Answers
- Program to find how many ways we can climb stairs in Python
- Program to find how many ways we can climb stairs (maximum steps at most k times) in Python
- In what ways hot water is better over cold water to drink?
- Program to find how many total amount of rain we can catch in Python
- C++ program to find maximum how many chocolates we can buy with at most k rupees
- Can the new Edible water bottle replace plastic bottles in the future?
- Program to find maximum number of coins we can collect in Python
- Program to find maximum number of coins we can get using Python
- Program to find maximum score we can get in jump game in Python
- Program to find maximum number of people we can make happy in Python
- Program to count how many times we can find "pizza" with given string characters in Python
- Program to find maximum credit we can get by finishing some assignments in python
- Program to find maximum coins we can get from disappearing coins matrix in Python
- Program to find out how many transfer requests can be satisfied in Python
- Program to find how many lines intersect in Python