3
// See the solution for this explanation4
int byPrimeFactorization(int n) {7
int factor = 2, ans = 0;9
while (n % factor == 0) {19
vector<int> dp(1001, INT_MAX);22
for (int i = 4; i <= n; i++) {23
dp[i] = i; // maximum number of operations required will be i24
for (int j = 2; j <= i / 2; j++) { // we copy and paste j A's till we have i A's25
int x = i - j; // we already have j A's in our stream, so remaining = i - j26
if (x % j == 0) { // if remaining number of A's is a multiple of J27
dp[i] = min(dp[i], dp[j] + 1 + (x / j)); // 1 operation to copy, x / j to28
// paste, dp[j] for getting j A's36
return byPrimeFactorization(n);