Created
December 30, 2017 01:17
-
-
Save thmain/b94c169db87461fbc2804b9446182fea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; //if yes then add no of smaller problems to result. If number = 25 i = 5 then 5*5 = 25 so add 5 to results | |
number=number/i; // create smaller problem | |
} | |
} | |
return res; | |
} | |
public static void main(String[] args) { | |
MinimumCopyPasteDP m = new MinimumCopyPasteDP(); | |
int n = 50; | |
System.out.println("Minimum Operations: " + m.find(n)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment