Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.lang.StringBuilder;
- public class MyClass {
- //Check Prime
- public static boolean isPrime(int n){
- for(int i=2;i<n/2;i++){
- if(n%i==0){
- return false;}
- }
- return true;}
- public static void main(String args[]) {
- long total=1;
- //Number to be tested
- int n=6;
- ArrayList<String> pFactors = new ArrayList<String>();
- //Convert to Factorial
- for( int i=0;i<(n);i++){
- total += total*i;}
- //Number to decompose
- long temp = total;
- for(int i=2;i<=temp;i++){
- int count =0;
- if(isPrime(i)){
- while(temp%i==0){
- count++;
- temp = temp/i;}
- //Output didnt want an exponent where the exponent is one
- if(count==1){
- pFactors.add(Integer.toString(i));}
- //Ignores any values where the exponent is zero
- else if(count>0){
- pFactors.add(Integer.toString(i) + "^" + Integer.toString(count));} // EG: 2^5. i=2 and count =5
- }
- }
- for(int i=0;i<pFactors.size();i++){
- System.out.println(pFactors.get(i));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement