difficulty with prob.3 on project euler (in c++) : <p>so, I've been trying to solve this problem for a few hours now. 
shortly I arrived to a solution that logically -  should work and is working, but only for numbers no bigger than 10^7. I guess I could just const the specific number they asked for (600851475143) but I would really love to know - why my code isn't working with big numbers?</p>

<p>this is my code for the solution :</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;
#include &lt;cmath&gt;

using namespace std;
//enter any number and its largest prime factor will be detected.
int main()
{
    long largest(1),num(0);
    bool primecheck;
    cout&lt;&lt;"enter the desired number :"&lt;&lt;endl;
    cin&gt;&gt;num;
    if (num%2==0)
        largest=2;
    cout&lt;&lt;"the relevant factors are: ";
    for (int i=3;i&lt;=int((sqrt(num))/2);i+=2)
        {
            primecheck=true;
            for(int j=2;j&lt;i;j++)
                {
                    if(i%j==0)
                        primecheck=false;
                }
            if(primecheck)
                if(num%i==0)
                {
                    largest=i;
                    cout&lt;&lt; largest&lt;&lt;"\t";
                }
        }
    cout&lt;&lt;endl&lt;&lt; "the largest prime factor of the number you have entered is: " &lt;&lt;largest;
    return 0;
}
</code></pre>

<p>thanks in advance! :)</p>
