Created
August 13, 2014 12:15
-
-
Save bmanojkumar/264ee0ea4eb58c6414e7 to your computer and use it in GitHub Desktop.
Refactoring
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
package refactoring; | |
import java.util.Scanner; | |
/** | |
* Created by manoj on 13/8/14. | |
*/ | |
public class java { | |
static int k = 0; | |
/* | |
* Eg: | |
* refactor(24,"",-1,24) --> refactor(12,"2",2,24) -> refactor(6,"2 2",2,24) -> refactor(3,"2 2 2",2,24) -> refactor(1,"2 2 2 3",2,24) | |
* -> refactor(2,"2 2 3",2,24) -> | |
* | |
* | |
* */ | |
static void refactor(int n,String t,int prev,String original) { | |
if(n == 1) { | |
if(!t.trim().equalsIgnoreCase(original)) | |
k++; | |
return; | |
} | |
for(int i=2;i<=n;i++) { | |
if(n%i == 0) { | |
if(prev <= i) | |
refactor(n/i,t + String.valueOf(i)+ " ",i,original); | |
} | |
} | |
} | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
refactor(n,"",-1,n+""); | |
System.out.println(k); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment