title: Largest Prime Factor algorithm optimization
body: <p>I'm trying to improve this interesting algorithm as much as I can.</p>
  
  <p>For now, I have this:</p>
  
  <pre><code>using System;
  
  class Program
  {
  
      static void Main()
      {
          ulong num, largest_pFact;
          uint i = 2;
          string strNum;
  
          Console.Write("Enter number: ");
          strNum = Console.ReadLine();
          num = ulong.Parse(strNum);
          largest_pFact = num;
  
  
          while (i &lt; Math.Sqrt((double) largest_pFact))
          {
              if (i % 2 != 0 | i == 2) {
                  if (largest_pFact % i == 0) 
                      largest_pFact /= i;
              }
  
              i++;
          }
  
          Console.WriteLine("Largest prime factor of {0} is: {1}", num, largest_pFact);
          Console.ReadLine();
  
      }
  }
  </code></pre>
  
  <p>So any ideas?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong>: I implemented Ben's algorithm, thanks eveyone for your help!  </p>