Skip to content

Instantly share code, notes, and snippets.

@thmain
Created December 30, 2017 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/b94c169db87461fbc2804b9446182fea to your computer and use it in GitHub Desktop.
Save thmain/b94c169db87461fbc2804b9446182fea to your computer and use it in GitHub Desktop.
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