
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ code to count number of notebooks to make n origamis
Suppose we have two numbers n and k. In a party there are n invited friends. Amal wants to make invitations in the form of origami. For each invitation, he needs two red papers, five green papers, and eight blue papers. There are infinite number of notebooks of each color, but each notebook consists of only one color with k papers. We have to find the minimum number of notebooks that Amal needs to buy to invite all n of his friends.
So, if the input is like n = 3; k = 5, then the output will be 10, because we need 2 red notebooks, 3 green notebooks, and 5 blue notebooks.
Steps
To solve this, we will follow these steps −
(2 * n + k - 1) / k + (5 * n + k - 1) / k + (8 * n + k - 1) / k
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; int solve(int n, int k){ return (2 * n + k - 1) / k + (5 * n + k - 1) / k + (8 * n + k - 1) / k; } int main(){ int n = 3; int k = 5; cout << solve(n, k) << endl; }
Input
3,5
Output
10
- Related Articles
- C++ code to count number of operations to make two arrays same
- C++ code to count number of weight splits of a number n
- C++ program to count minimum number of operations needed to make number n to 1
- C++ code to count operations to make array sorted
- C++ code to count number of unread chapters
- C++ code to find maximum fruit count to make compote
- C++ code to count number of packs of sheets to be bought
- C++ code to count number of even substrings of numeric string
- C++ code to count number of dice rolls to get target x
- C++ code to count number of times stones can be given
- C++ code to count number of lucky numbers with k digits
- C++ program to count number of dodecagons we can make of size d
- Program to count minimum number of operations to flip columns to make target in Python
- Program to count number of minimum swaps required to make it palindrome in Python
- C++ code to count volume of given text

Advertisements