Jan 27, 2012 at 7:40pm UTC
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 UTC
unsigned long long:
18446744073709551615
20 digits.
Jan 27, 2012 at 7:45pm UTC
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 UTC
Jan 27, 2012 at 7:49pm UTC
'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 UTC
Jan 27, 2012 at 7:53pm UTC
Nice!
*system32 now gone*
Jan 27, 2012 at 7:56pm UTC
Oh wait, long long still isnt working according to GCC
Jan 27, 2012 at 7:57pm UTC
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 UTC
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 UTC
Jan 27, 2012 at 8:11pm UTC
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 UTC