
- 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 order collected when client calls
Suppose we have three numbers n, m and z. An office receives calls in every n minutes, and some deliveries come to office in every m minutes. Office is open for z minutes. We have to count the minimum number of orders are collected so there are no pending orders when client calls. Consider taking orders and talking with clients take exactly 1 minutes.
So, if the input is like n = 1; m = 2; z = 5, then the output will be 2, because we need to collect orders which comes in second and fourth minutes.
Steps
To solve this, we will follow these steps −
return z / ((n * m) / (gcd of n and m))
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; int solve(int n, int m, int z){ return z / ((n * m) / __gcd(n, m)); } int main(){ int n = 1; int m = 2; int z = 5; cout << solve(n, m, z) << endl; }
Input
1, 2, 5
Output
2
- Related Articles
- C++ code to count number of unread chapters
- C++ code to count volume of given text
- C++ code to count who have declined invitation
- C++ code to count operations to make array sorted
- C++ code to count days to complete reading book
- C++ code to count ways to form reconnaissance units
- C++ code to count copy operations without exceeding k
- C++ code to count local extrema of given array
- C++ code to count maximum groups can be made
- C++ code to count maximum banknotes bank can gather
- C++ code to find maximum fruit count to make compote
- Determining the current client in SAP using code
- C++ code to count maximum hay-bales on first pile
- C++ code to count number of notebooks to make n origamis
- C++ code to count colors to paint elements in valid way

Advertisements