• Coding
  • A little help with long long in C++

So since I have to program with C++ for the programming competition, and exercise 2 needs long long to store the number 600,851,475,143, I went ahead with it. I remember from last time I used it that this data type has a range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. However, when I used it the C-Free GCC compiler gave me an error indicating that the number is too big to use with long long. I tried to use __int64 instead, still same problem. I tried to use unsigned long long since it has a larger range of 0 to 18,446,744,073,709,551,615, but to no avail.

If it were a memory issue, even Matlab should have given me an error ( I used num2str to find first 2 prime factors since functions primes and factor can only acquire numbers up to 2^23 = 4294967296). What should I do?

PS: I once had an assignment to use linked lists to reserve really large integers and overload operators to handle them arithmetically, bu they're a hassle and I really don't want to use it!
you have to include the library containing this data type.
#include<iostream>
using namespace std ;

#include<stdint.h> //to use the unit64_t data type and other types, download the library if it is not included

void main(){
	uint64_t number = 600851475143 ;
	cout<<number ; //worked perfectly
}
http://en.wikipedia.org/wiki/Stdint.h check this for more info.
You can use a long, it should be enough. It is coded on 8 bytes (64bits), which is largely sufficient.
rahmu wroteYou can use a long, it should be enough. It is coded on 8 bytes (64bits), which is largely sufficient.
I know rahmu, but it gives me the following error:
[Error] C:\Users\Alaa Salam\Desktop\Programming competition\Exercise 2\Prime number identification.cpp:37: error: integer constant is too large for "long" type
At first I was shocked, so I resorted to long long instead, but still same problem
What compiler are you using?

I think the error comes from something else, an operation you're doing on the variable. Can you copy your code, or at least line 37 of it?
rahmu wroteWhat compiler are you using?

I think the error comes from something else, an operation you're doing on the variable. Can you copy your code, or at least line 37 of it?
I'm using C-Free 5 (also tried it on Borland 5.0). If the error was from the code, then it wouldn't have worked for 10086647 which is the product of the largest two prime numbers of 600851475143.

Anyway, I'll PM you the code.
rahmu, what's the latest about the code?
long long is not a standard c++ type. you would need a compiler with 64bits support.
first of try including stdint.h then check from that header file to see how they actually define int64_t
if they do not i think u better upgrade ur compiler.
gcc 4.3.0 , vc++ 2005&2008 support long long types. in gcc i thnk u must put LL after the integer itself.
C-Free has the ability to select form one of the following compilers:

- MinGW
- Borland C++
- Intel C/C++
- Digital Mars C/C++
- Ch
- Cygwin

I'm selecting the compiler MinGW since it supports 64-bit operations according to the imported library stdint.h which I checked and is avaliable so both int64_t and uint64_t are supported as well as __int64 from the main library _mingw.h. The compiler I have is the latest version (MinGW 5.1.4)
placing the LL at the end resulted in nothing
any other suggestions?