No type large enough?

Jan 27, 2012 at 7:40pm
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
Jan 27, 2012 at 7:44pm
unsigned long long:
18446744073709551615

20 digits.
Jan 27, 2012 at 7:45pm
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 Jan 27, 2012 at 7:46pm
Jan 27, 2012 at 7:49pm
'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 Jan 27, 2012 at 7:49pm
Jan 27, 2012 at 7:49pm
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'.

Jan 27, 2012 at 7:53pm
Nice!
*system32 now gone*
Jan 27, 2012 at 7:56pm
Oh wait, long long still isnt working according to GCC
Jan 27, 2012 at 7:57pm
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!!
Jan 27, 2012 at 8:01pm
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 Jan 27, 2012 at 8:01pm
Jan 27, 2012 at 8:10pm
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;
}
Jan 27, 2012 at 8:11pm
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 Jan 27, 2012 at 8:14pm
Topic archived. No new replies allowed.