prime numbers

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
udvat
New poster
Posts: 29
Joined: Thu Aug 07, 2003 9:56 pm

prime numbers

Post by udvat »

say i have to find out whether a=2^31 is prime or not.
but i cant do it by testing if a is divided by the primes between sqrt(a),cause it results in TLE.what should i do then?

is there any efficient method to find primes within a range?can we use seive to find primes in [a,b] ?i mean we should not start seive from 2 but from later numbers.
Alessandro
New poster
Posts: 27
Joined: Mon Jun 14, 2004 10:33 pm
Location: Latina, Italy

Post by Alessandro »

For large numbers you can use probabilistic primality testing. This test give result with a certain % of probability to be correct, but with "small" numbers (with less of 500 ciphers, and such numbers aren't big for numbers theorists) it's OK.

But I don't know where you can see the probabilistic primality testing :) Friends talked to me about that.

For the primality in the range... you can search the net for sieves. I don't remeber now, but I found a very fast sieve long ago...

Goodbye
Ale
Alessandro Piva, Member of the Italian Team at the International Olimpiad in Informatics 2004
Email: alex.ander@infinito.it
abishek
Experienced poster
Posts: 131
Joined: Mon Dec 15, 2003 5:41 am

Post by abishek »

miller rabin test is a very good probablistic test.
fermat's test is also nice, but all the carmichael numbers pass it so it is not used.
you can google for miller rabin and you will find hundreds of results.

well for the theory,

there are elliptic curve based methods that can be used to prove that a number is prime with certainity. also there is the latest algorithm which tests primality in P. but i think those are not for UVA. i haven't even used miller rabin.

if someone finds a sum using miller rabin, kindly point it out. i'd like to try my code.

bye
abi
Post Reply

Return to “Algorithms”