java codeeval ugly number
<p>This question is from <a href="https://www.codeeval.com/open_challenges/42/" rel="nofollow">https://www.codeeval.com/open_challenges/42/</a>
I got score 89.29, the website seems running a bit long for my algorithm. Is that my algorithm is of low efficiency?
I used BigDecimal to deal with prefix 0 and used "X" to split String into parts.
sig[] is used to store null or +, -.</p>

<pre><code>import java.math.*;
import java.io.*;
public class ugly_numbers {

public static boolean ugly(int n){
    return n%2==0|n%3==0|n%5==0|n%7==0;
}
public static boolean test(String s,int n,int len){
    StringBuffer sb=new StringBuffer(s);
    int sig[]=new int[len];
    for(int i=0;i&lt;len;i++){
        sig[i]=n%3;
        n/=3;
    }
    int off=1;
    for(int i=0;i&lt;len;i++){
        if(sig[i]!=0){
            sb.insert(i+off++, 'X');
        }
    }
    String fin=sb.toString();
    String[] fins=fin.split("X");
    int loc=1;
    BigDecimal res=new BigDecimal(fins[0]);
    for(int i=0;i&lt;len;i++){
        if(sig[i]==1){
            res=res.add(new BigDecimal(fins[loc++]));

        }
        else if(sig[i]==2){
            res=res.subtract(new BigDecimal(fins[loc++]));
        }
    }
    int tst=res.intValue();
    return ugly(tst);

}
public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    BufferedReader br=new BufferedReader(new FileReader(args[0]));
    String input;
    while((input=br.readLine())!=null){
        input.trim();
        int len=input.length();

        int all=(int) Math.pow(3, len-1);
        int res=0;
        for(int i=0;i&lt;all;i++){
            if(test(input,i,len-1))
                res++;


        }
            System.out.println(res);
        }
        br.close();
    }

}
</code></pre>
