- 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

# C++ code to count number of packs of sheets to be bought

Suppose we have four numbers k, n, s and p. To make a paper airplane, Rectangular piece of papers are used. From a sheet of standard size we can make s number of airplanes. A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the other people. Each person should have enough sheets to make n different airplanes. We have to count the number of packs should we buy?

So, if the input is like k = 5; n = 3; s = 2; p = 3, then the output will be 4, because they have to buy 4 packs of paper: there will be 12 sheets in total, give 2 sheets to each person.

## Steps

To solve this, we will follow these steps −

ans := k * ((n + s - 1) / s) return (ans + p - 1) / p

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; int solve(int k, int n, int s, int p){ int ans = k * ((n + s - 1) / s); return (ans + p - 1) / p; } int main(){ int k = 5; int n = 3; int s = 2; int p = 3; cout << solve(k, n, s, p) << endl; }

## Input

5, 3, 2, 3

## Output

4

- Related Questions & Answers
- C++ code to find the number of refill packs to be bought
- C++ code to count number of times stones can be given
- Maximum number of candies that can be bought in C
- C++ code to count number of unread chapters
- C++ code to count number of weight splits of a number n
- C++ code to count number of even substrings of numeric string
- Program to find maximum number of package that can be bought by buyers in C++
- C++ code to count number of notebooks to make n origamis
- C++ code to count number of operations to make two arrays same
- C++ code to count number of dice rolls to get target x
- C++ code to count number of lucky numbers with k digits
- C++ code to count maximum groups can be made
- C++ code to count volume of given text
- C++ Program to count number of characters to be removed to get good string
- C++ code to count local extrema of given array