Because isn’t fast
Google is your best friend, then ask him: “how to check if number is prime” or on Wikipedia: “primality test”.
isn't k*k <= j enough?
if (j % k == 0) flag1 = false; // <-- why didn't you break the loop after that?
Why you don’t delete all comments in your code?
You should check what is different between long int, long long int and long long [on 32 and 64 bits systems] and if int is enough in this problem.