If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Prime Numbers

Originally Posted by rockx

so Eri523, what exactly would you suggest.

Get a better editor, one that is designed to open large files.

and this failed the windows from opening the file

Windows didn't fail.

You didn't mention what you used to open the file. I can open files much larger than 512 MB using editors that are designed to open and manipulate large files. If you're using Notepad, then don't use it, and instead use another editor such as EMEditor or another that allows large file editing.

Re: Prime Numbers

Re: Prime Numbers

Before you decide on the format of the output file from your prime number generation program, you need to know the kind of analysis that is going to be performed on this data and by what method. If you intend to produce even a Trillion prime numbers then you are going to produce very large size files. When dealing with files of this size, the method of access becomes important so the format of the file becomes much more critical to performance issues.

Also, you are going to hit problems with the range of numbers that can be stored within the program variables. Currently the program as posted uses long int (ie signed) so the maximum number that can be stored is 2,147,483,647. Even moving to unsigned long gives a maximum number of 4,294,967,295. So if you want trillions of prime numbers, your program is going to have to move to 64 bit numbers.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Prime Numbers

Maybe unsigned long long, but beware that it might not be available as it is a recent addition to the C++ standard. Or, maybe you need to use an arbitrary precision arithmetic library.

At this point, my take is that you need to do some more experimentation first. Yesterday, you didn't even know that brute force primality testing only needed to be done with possible (prime) factors until the square root of the candidate number. Take your time and experiment with say, finding and recording the first few million primes before you start planning on a billion. Experiment with getting a billion before you start deciding on how to handle a trillion.

Oh, and what analysis do you intend to do? You still have not answered this question.

And the question on analysis, well nothing tooo big and nothing too serious. and not really analysis, i might keep the record for future references, i dont really know when i might need them. If i get to learn to do something with it in the future then i guess this should be a good start off for me

Re: Prime Numbers

Oh, I think this is the reason why MS Word could not open your file:

Code:

ofstream myfile ("PrimeNumbers.doc");

My guess is that Word expected your file to be in Microsoft's Word document format, but it was merely a plain text file, hence the error. If you had used say, a ".txt" or ".csv" file extension instead, then perhaps it would have treated the file differently by default.

By the way, I suggest that you don't use tab characters to pretty align your code. Using tab characters for indentation is fine, but alignment with tabs is generally a bad idea because tab widths depend on the editor settings.

Re: Prime Numbers

Originally Posted by laserlight

Oh, I think this is the reason why MS Word could not open your file:

Code:

ofstream myfile ("PrimeNumbers.doc");

My guess is that Word expected your file to be in Microsoft's Word document format, but it was merely a plain text file, hence the error. If you had used say, a ".txt" or ".csv" file extension instead, then perhaps it would have treated the file differently by default.

I'd have assumed that Word at least checks the file signature to verify it's a valid .doc file, and in case of failure falls back to opening it as plain text. However, after reading your post, I did a real-life check on that with my Word 2003 (newer versions may perhaps behave differently). I renamed a plain text file to .doc and attempted to open it in Word. After dismissing a few error message boxes informing me that Word was unable to start some converter, it opened the file as plain text perfectly fine. Maybe it's simply the OP's file being too large? Note, however, that the file I did the test with didn't contain tabs, which may have influenced the result, due to Word attempting to auto-detect the file format.

I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.