#include
main()
{
long n=600851475143;
int i,j,flag;
for(i=2;i<=n/2;i++)
{
flag=1;
if(n%i==0)//finds factors backw
On 32-bit machine long
range from -2,147,483,648
to 2,147,483,647
and On 64-bit machine its range is from -9,223,372,036,854,775,808
to 9,223,372,036,854,775,807
(NOTE: This is not mandated by C standard and may vary from one compiler to another).
As OP said in comment he is on 32-bit, 600851475143
goes out of range as it is not fit in the range of long
.