Computing.Net > Forums > Programming > BigInteger Array

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

BigInteger Array

Reply to Message Icon

Name: Hippie Joe
Date: November 4, 2002 at 15:43:23 Pacific
OS: RedHat8
CPU/Ram: 933
Comment:

hello everyone. i am playing around with generating prime numbers using the isProbablePrime function in the BigInteger class. However, I would like to generate a very large number of primes in sequential order. I have this part figured out, however i would like to store them all in an array of a given size. is this possible? if so how do i do it? thanks very much.



Sponsored Link
Ads by Google

Response Number 1
Name: Hippie Joe
Date: November 4, 2002 at 16:59:13 Pacific
Reply:

--- More BigInteger Stuff ---

is there anyway to set a variable as type BigInteger and place a value into that

for ex. BigInteger temp=5;

my goal is to fill an array (see above) with say the first 100,000 primes. i want to do this with testing every odd number untill the array is filled. so basically i would like to say...

BigInteger value = 3;

while (position{
if(value.isProbablePrime(50))
{
array[position]=value;
position++;
}
else
System.out.println(value + "not prime");

value=value+2
}

syntax not the best, but i hope it gives a general idea. if anyone knows how this can be done please let me know. if this is not possible, please let me know that as well...could save some headaches. thanks everyone.


0

Response Number 2
Name: Trip
Date: November 5, 2002 at 10:50:28 Pacific
Reply:

Just wanted to comment that testing every odd number for prime gives very poor performance. A much faster way is to check numbers against previously found primes, up to the squareroot of the number. Since you are already trying to store primes in an array this is fairly easy and you don't have to use custom defined types, the standard int or long int should be fine. The code is pretty quick, giving about 1000 primes per sec here when printed to the screen, probably much faster if the output was omitted or sent to a file.

The code won't format well posted here, so:
http://66.24.125.81/prime.cpp



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: BigInteger Array

VB Array Problem www.computing.net/answers/programming/vb-array-problem/6020.html

The array again!! www.computing.net/answers/programming/the-array-again/1505.html

internal structudre of Array in C++ www.computing.net/answers/programming/internal-structudre-of-array-in-c/939.html