#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
Try changing n to long long int .. and change i,j to long
n
long long int
EDIT: define n like this :
long long int n = 600851475143LL;
LL - is a suffix to enforce long long type ...
LL