Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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