0

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.

Avi
  • 21,182
  • 26
  • 82
  • 121

4 Answers4

8
long long n = 600851475143LL;

Appending LL makes it a long long literal. By the way, long long has not been standardized until C++11.

jdh8
  • 3,030
  • 1
  • 21
  • 18
2

Put an LL after it.

long long n=600851475143LL;
Tom van der Woerdt
  • 29,532
  • 7
  • 72
  • 105
1

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.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165
  • As I understand it, that's a C++11 feature. For C++98, this isn't a bug. – Philip Kendall Jul 12 '13 at 13:06
  • @PhilipKendall - `long long` comes from C99, and C99 has the same requirement here. Regardless, supporting `long long` but not supporting implicit typing of integer constants is obviously a bug. – Pete Becker Jul 12 '13 at 13:24
1

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.

lulyon
  • 6,707
  • 7
  • 32
  • 49