No type large enough?

So, I'm actually working through these project euler things cause im bored. Anyways, ran into a problem where I need to find the large prime factor of a number, but this number is too large to fit in a data type. Right now I have an unsigned long int, and that is not enough for this number. It's a 12 digit number
unsigned long long:
18446744073709551615

20 digits.
I actually just tried an unsigned long long
GCC still gives me an error, saying that "integer constant is too large for 'long' type".

EDIT:
Never mind, I'm dumb. Didn't clear out my build log haha
Last edited on
'unsigned long int' is the same as 'unsigned', which is probably 32 bits.

You can get to 64 bits by using 'long long' (signed or unsigned). That is plenty big enough for a 12 digit number.

EDIT: wow I'm slow. hahaha
Last edited on
ahaha!

Here's a small program I made, it just prints ranges for data types:
http://sites.google.com/site/davevisone/home/cplusplus/random_cpp/random_cpp_downloads

The 'c++ Ranges.zip'.

Nice!
*system32 now gone*
Oh wait, long long still isnt working according to GCC
lol, nothing like that at all!

I don't have the source code for that anymore, but I'd gladly record my screen, me downloading it and then running it!

And I can't change it after downloading it, because it will change to v.2 on the download page.

I wouldn't jeopardize my account on here! I come on here almost every day!!
If you are using GCC, you can #include "stdint.h", and then use the uint64_t type which is the native type for a 64 bits unsigned integer.

Take a look at : http://en.wikipedia.org/wiki/C_data_types

I use it on MinGW...
Last edited on
I'm using VC++ and the following code works fine:
1
2
3
4
5
6
7
8
9
#include <iostream>	// cout

int main( int argc, const char *argv[] )
{
	unsigned long long i = 18446744073709551615;
	std::cout << i << '\n';

	return 0;
}
Hmm, maybe cl has a larger long long? I'll give a look at my VS and see what I get

EDIT:
Yup, this works in my VS2010

1
2
3
4
5
6
7
8
int main(){
unsigned long long i = 1234567890123;

  cout << i;
  cin.get();

return 0;
}
Last edited on
Topic archived. No new replies allowed.