title: Optimizing digit <= 2 algorithm (similar to Project Euler 303)
body: <p>I'm creating a program to solve <a href="http://projecteuler.net/problem=303" rel="nofollow">Project Euler Problem 303</a>
  My method to find  <code>f(n)</code> is barely short of brute force:</p>
  
  <pre><code>static BigInteger findFn(int n){
      Long Fn = new Long(n); 
      String test = Fn.toString();
      Long multiplier = new Long("1"); 
      long counter = 0;
      boolean done = false; 
      BigInteger fn = new BigInteger("0");
      while(!done){
          counter = 0; 
          BigInteger tempOne = new BigInteger(multiplier.toString());
          BigInteger tempTwo = new BigInteger(Fn.toString());
          BigInteger product = tempOne.multiply(tempTwo);
          test = product.toString();
          for(int i = 0; i &lt; test.toString().length(); i++){
              if(Character.getNumericValue(test.toString().charAt(i)) &lt;= 2){
                  counter++;
              }else{
                               //Is it better to set done = true here as opposed to breaking?
                  break; //breaks if it encounters any number in the multiple &gt;2. 
              }
  
          }
  
          if(counter == test.length()){
              fn = product;
              done = true;
              break;              
          }
          multiplier++;
      }
      return fn;
  }
  </code></pre>
  
  <p>It works well on most numbers, but there are a few (usually those that end in 9) that it just gets stuck on. 
  I think that the BigIntegers slow it down, so firstly, is there anywhere I've used a BigInteger where it isn't necessary?
  Secondly, there has to be either an alternate method or some sort of other trick to cut down on the number of loops that I haven't thought of. 
  Any thoughts to give me a push in the right direction? </p>
  
  <p>Thanks!!</p>