Computer Science, asked by adityasuru, 7 months ago

Alex is a notorious boy. He plans to spam the same text multiple times on a messenger group. He has typed the text once in the text box, and wants to type that text N times before sending it. Being lazy, he adds the remaining text in the text box using copy and paste operations as mentioned below: Copy Operation - Copies all the text currently

in the text box and save it onto a buffer. Paste Operation - Append the text saved in the buffer to the text box.

Write an algorithm to help Alex send a text in the minimum number of operations,​

Answers

Answered by amolsachdeva
0

Answer: #include <iostream>

using namespace std;

int find(int num)

{

int res = 0;

for(int i=2;i<=num;i++)

{

while(num%i == 0)

{

res+= i;

num=num/i;

}

}

return res;

}

int main()

{

int n;

cin>>n;

cout<<find(n);

}

Explanation: please choose C++ language

Answered by sujan3006sl
0

Answer:

public class MinimumCopyPasteDP {

public int find(int number){

int res = 0;

for(int i=2;i<=number;i++){

while(number%i == 0){ //check if problem can be broken into smaller problem

res+= i;

number=number/i;

}

}

return res;

}

public static void main(String[] args) {

MinimumCopyPasteDP m = new MinimumCopyPasteDP();

int n = 50;

System.out.println("Minimum Operations: " + m.find(n));

}

}

Explanation:

  • In the worst scenario, to get the desired outcome, the character must be copied and pasted N times.
  • In order to decrease the number of processes, we must minimise the necessity to paste, which entails performing the copy action whenever feasible. If N is 50, for example, printing 25 As followed by a copy and paste operation will print 50 characters. In order to get to 25, which is a multiple of 5, we must first print 5 As, copy them, and then paste them four more times to acquire 25 As. We must then print 5 As again by copying and pasting the previous A.

Examples

N = 50, printed – A

Copy and paste it 4 times – printed – AAAAA, operations – 5

Copy and paste it 4 times – printed AA…..AA (25), operations – 5 + 5 = 10

Copy and paste – printed – AA…AAA (50 A’s), operations – 10 + 2 = 12

#SPJ3

Similar questions