title: Fermat Algorithm for prime factors calculation
body: <p>According to youtube <a href="https://www.youtube.com/watch?v=Uigp4aLP2eM" rel="nofollow">link</a> <strong>the prime factors</strong> of an odd number can be calculated as follows:</p>
  
  <p>a = sqrt(N + b^2)</p>
  
  <p>I wrote below program to do that but I am not getting the prime factors of 2345678917. I know this is prime number but for other prime numbers the program does return 1 and the number itself but for this number it is not happening. Why?</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  void foo(unsigned long long x)
  {
      int i;
      for (i=1;i&lt;x;i++)
          if (fmod(sqrt(x + i*i), 1) == 0) {
              printf("%f %f\n", (sqrt(x + i*i) - i), (sqrt(x + i*i)+i));
              return;
          }
  }
  
  int main(void) {
      foo((unsigned long long)2345678917);
      return 0;
  }
  </code></pre>