当客户端调用时计算收集的订单的 C++ 代码


假设我们有三个数字 n、m 和 z。一个办公室每隔 n 分钟收到一通电话,每隔 m 分钟收到一些送货。办公室开业 z 分钟。我们必须统计最少收集多少个订单才能在客户端打电话时没有待处理订单。请考虑接单和与客户交谈需要正好 1 分钟。

因此,如果输入类似于 n = 1; m = 2; z = 5,那么输出将为 2,因为我们需要收集在第二分钟和第四分钟来的订单。

步骤

为了解决这个问题,我们将遵循以下步骤 −

return z / ((n * m) / (gcd of n and m))

示例

让我们查看以下实现,以获得更好的理解 −

Open Compiler
#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; }

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

输入

1, 2, 5

输出

2

更新时间: 15-3-2022

252 次浏览

开启您的 职业

完成课程以获得认证

开始
广告