prime generation
Moderator: Board moderators
prime generation
I have to find out the primes within the range 100000000. but i dont have the option of having a large array(so i cant use seive). wud anybody plz give me the solution?the code should be faster.
help me
thankx to u all. am sending my code here. the judge says my code takes a long time to compile and it may because of using more than 16 mb of memory.its a problem from usaco training gateway.name is"prime palindrom"
************code has been removed
************code has been removed
Last edited by udvat on Tue Nov 18, 2003 5:05 pm, edited 1 time in total.
Re: help me
u can try this:udvat wrote:thankx to u all. am sending my code here. the judge says my code takes a long time to compile and it may because of using more than 16 mb of memory.its a problem from usaco training gateway.name is"prime palindrom"
only generate the prime under 10000 (since the square root of 100000000 (i hope i didn't mislook; there are 8 zeros) is 10000), then when u try to determine whether a number is a prime or not, try to divide it with all the primes from 2 to the square root of the number (that's why we only generate the prime under 10000, 'cause we have enough prime to determine number up to 100000000). if none of them can exactly divide your number, it's a prime; otherwise, it's not a prime.
according to my experience, there are about 12000 primes under 10000(if my memory is right

hope this'll be helpful

-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore
Now that I read through my post again I guess I wasn't too clear before. Actually I meant that you generate the palindromes and then check whether they are primes. This will be faster than check every number. Then you can store these palindrome primes into an array and check against the range in the input.
thankx junjieliang
yes, its a good idea. i will try it. thank u very much 
