-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsolution.java
More file actions
21 lines (19 loc) · 747 Bytes
/
solution.java
File metadata and controls
21 lines (19 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public int minSteps(int n) {
// Initialize the number of operations required to 0
int operations = 0;
// Start checking for divisors from 2 up to n
for (int i = 2; i <= n; i++) {
// While 'n' is divisible by 'i', keep dividing and count the operations
while (n % i == 0) {
// Add 'i' to the operations count as each division represents 'i' copy-paste
// operations
operations += i;
// Divide 'n' by 'i' to reduce 'n' for further factorization
n /= i;
}
}
// Return the total number of operations required to achieve 'n' 'A's
return operations;
}
}