c++ numbers out of range

 Posts: 2
 Joined: Mon Nov 15, 2010 1:00 am
c++ numbers out of range
i'm new here
i was wondering if you could tell me how can i solve this problem.
for some excercises, i need to work with big numbers, but sometimes the console gives me numers like 1.150e1651 etc.
so i can't work with big numbers,
i only know int, float, double but none of this worked for me,
maybe i'm doing something wrong.
i was wondering if you could tell me how can i solve this problem.
for some excercises, i need to work with big numbers, but sometimes the console gives me numers like 1.150e1651 etc.
so i can't work with big numbers,
i only know int, float, double but none of this worked for me,
maybe i'm doing something wrong.
Re: c++ numbers out of range
Welcome to PE latinpower!
C++ also has 64bit integers ("long long" or "__int64" depending on which implementation you use).
As a principle, you don't need any bigInt or bigNum libraries to solve the PE problems (but you do need to know the limitations imposed by each type and take those limitations into consideration when you formulate your solutions).
C++ also has 64bit integers ("long long" or "__int64" depending on which implementation you use).
As a principle, you don't need any bigInt or bigNum libraries to solve the PE problems (but you do need to know the limitations imposed by each type and take those limitations into consideration when you formulate your solutions).

 Posts: 18
 Joined: Thu Jan 20, 2011 2:06 am
Re: c++ numbers out of range
How do you suggest solving problems like 16 and 97 without bignums?harryh wrote:Welcome to PE latinpower!
C++ also has 64bit integers ("long long" or "__int64" depending on which implementation you use).
As a principle, you don't need any bigInt or bigNum libraries to solve the PE problems (but you do need to know the limitations imposed by each type and take those limitations into consideration when you formulate your solutions).
Re: c++ numbers out of range
97 doesn't need big integers whatsoever.
I guess you could say 16 does; but to be honest if you didn't have a big integer library, writing some code to calculate what is required is less code than you'll need for most other problems. It's just another algorithm.
I guess you could say 16 does; but to be honest if you didn't have a big integer library, writing some code to calculate what is required is less code than you'll need for most other problems. It's just another algorithm.
 euler
 Administrator
 Posts: 3318
 Joined: Sun Mar 05, 2006 4:49 pm
 Location: Cheshire, England
 Contact:
Re: c++ numbers out of range
Way back when PE started many programming languages did not have native big number capabilities  nor were such libraries readily available  so the purpose of producing some of those earlier problems was to get people to think about how these fundamental arithmetic operations (including modulo arithmetic) is tackled. Problem 16 should be a fun example which allows you to create your own multiplying algorithm.browni3141 wrote:How do you suggest solving problems like 16 and 97 without bignums?
To explicitly state it... the difference, which Harry mentions, is that generally for those earlier problems the actual problem itself is the "big number" calcuation; this should be obvious from the problem. Whereas for the more recent problems the challenge itself is something quite different. So during problem development the size of integers required (or degrees of precision) are limited to common limitations of most programming languages. However, there may be rare occasions when this general principle needs to be overridden, but that would be stated in the problem.
impudens simia et macrologus profundus fabulae

 Posts: 18
 Joined: Thu Jan 20, 2011 2:06 am
Re: c++ numbers out of range
Thank you for your replies. I did enjoy coming up with an algorithm for those problems. I realize it would be ridiculous to try 97 with bignums.
Re: c++ numbers out of range
Well, since I see there's already a topic on it (plus do we really have to abide by that one thread per programming language thing?), I was thinking I see at least a couple more problems where storing large numbers is going to be a must. I was wondering if instead of having to reinvent the wheel each time if it would be smarter to write up a class for this sort of thing and somehow include it in future programs that might need it. Which means I'll likely need to relearn how to do classes and figure out where my compiler looks for usermade include files...
As I said, I've spotted at least 3 where something like this might be handy. Anyone more familiar with the problems think something like this might be warranted? Without giving anything away, any suggestions on what kind of functionality I might want to include for such a class or should I just try to add to it as needed?
As I said, I've spotted at least 3 where something like this might be handy. Anyone more familiar with the problems think something like this might be warranted? Without giving anything away, any suggestions on what kind of functionality I might want to include for such a class or should I just try to add to it as needed?
Re: c++ numbers out of range
I don't always use the same language to work out problems. Some of the languages, like Unix's bc, and scheme have big number support. Perl has a module you can load. There are C & C++ bignum libraries. So, while i worked out how to do problem 97 in C without bignums, I kicked it off in bc. I mean, i couldn't quite copy and paste the problem into bc  i had to type it in bc's syntax. But it could not have taken me more than a few seconds. Linux is really good at doing more than one thing at a time, so i started coding the other solution in another window. But bc beat me by quite a bit, generating over 2 million digits of the full answer, dumping the answer to a file.

 Posts: 16
 Joined: Sun Mar 02, 2014 2:32 pm
Re: c++ numbers out of range
You can and should do 97 without big integers (a 64bit type will do.) It should take almost zero processing time  there is a logtime algorithm that is ideal for it, and easily written.