title: Largest prime factor - euler project
body: <p>I was trying to solve project Euler <a href="http://projecteuler.net/problem=3" rel="nofollow">problem 3</a> which is:</p>
  
  <p><strong><em>The prime factors of 13195 are 5, 7, 13 and 29.
  What is the largest prime factor of the number 600851475143 ?</em></strong></p>
  
  <p>Here is my solution , it works for smaller values but somehow doesn't complete for the required number:</p>
  
  <pre><code>public class Pro3 {
      public static void main(String[] args) {
          long l=600851475143L;
          for(long lo=l/2;lo&gt;=2;lo--){
              if(l%lo==0 &amp;&amp; isPrime(lo)==true){
                      System.out.println(lo);
                      break;
              }
          }
      }
  
      static boolean isPrime(long x){
          for(int i=2;i&lt;=Math.sqrt(x);i++){
              if(x%i==0){
                  return false;
              }
  
          }
          return true;
      }
  }
  </code></pre>