#282-Step Document Printing
A printing machine starts with one copy of a document on its screen. For each step, the operator can perform one of two actions: Copy All: Copy all currently displayed documents. Paste: Add all documents from the most recent copy operation to the current display.
Given an integer n, return the minimum number of operations required to produce exactly n copies of the document. A partial copy is not allowed.
Real World Application
- Document duplication
- Data replication
- Cloud resource scaling
- Database replication
- File/folder cloning
- VM cloning
- Batch production
- Inventory duplication
Examples
Example 1
Input: n = 3
Output: 3
Explanation: Initially: Documents = 1 Operations: Copy All → 1 Paste → 2 Paste → 3 Total operations = 3
Example 2
Input: n = 1
Output: 0
Explanation: The machine already has one document, so no operation is required.
Example 3
Input: n = 6
Output: 5
Explanation: Start: 1 Copy All → 1 Paste → 2 Operations: Copy All → 2 Paste → 4 Paste → 6 Total = 5 operations
Constraints
- 1 <= n <= 1000
