I am using Dev C++
the erratic line is...
long long n=600851475143;
error description:
integer constant is too long for "long" type
I need help in dealing with big numbers.
I am using Dev C++
the erratic line is...
long long n=600851475143;
error description:
integer constant is too long for "long" type
I need help in dealing with big numbers.
long long n = 600851475143LL;
Appending LL
makes it a long long
literal. By the way, long long
has not been standardized until C++11.
Put an LL after it.
long long n=600851475143LL;
Integer constants with no suffix get the smallest of int
long int
and long long int
that can hold the value (2.14.2, Table 6), so, assuming that long long
is needed for this value, 600851475413
has type long long
. From the error message, it looks like the compiler is treating the constant as type long
instead of long long
. So adding LL
is a workaround for a compiler bug.
It seems your compiler(g++?) do not support long long type well, and numbers should be suffixed with LL, which is not supported in Visual C++. Try __int64 instead for n:
__int64 n=600851475143;
Both gcc and Visual C support __int64 on Windows.