Ask your own question, for FREE!
Mathematics 20 Online
OpenStudy (dan815):

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? some methods of finding

OpenStudy (dan815):

wait ok no forget that!! start over

OpenStudy (anonymous):

http://www.sosmath.com/tables/prime/prime.html

ganeshie8 (ganeshie8):

to test if 'n' is a prime :- you need to test all the prime numbers < sqrt(n)

OpenStudy (dan815):

this is more of a math/ computer algorithm question, need to find efficient ways of adding primes to list

OpenStudy (dan815):

yeah ganeishi but just

OpenStudy (dan815):

i realized 13 wasnt given it was found so, what would you suggest best way if you just must find the prime too

ganeshie8 (ganeshie8):

there will be primes that differ by 2 : (11, 13), (17, 19)

ganeshie8 (ganeshie8):

so, we need to test each and every ODD number

OpenStudy (dan815):

is there better way, that is lots of function time

ganeshie8 (ganeshie8):

let me get this clear :- you're saying testing for prime factors < sqrt(n) is a lot of function time ?

OpenStudy (dan815):

no

OpenStudy (dan815):

n is not given

ganeshie8 (ganeshie8):

oh, basically u want to create list of all prime number ?

OpenStudy (dan815):

yeah

ganeshie8 (ganeshie8):

@mukushla is here :)

OpenStudy (dan815):

but i see what u are suggesting that is not a bad way to go about it too

OpenStudy (dan815):

take every odd number sqrt it and keep checking permutations of our existing prime list?

ganeshie8 (ganeshie8):

nope. just check if a 'single' prime factor exists thats less than sqrt of it

OpenStudy (dan815):

ok so say for 13

ganeshie8 (ganeshie8):

if \(n\) is not a prime , there will be atleast one prime factor < \(\sqrt{n}\)

OpenStudy (dan815):

id do 13 mod 2 13 mod 3

OpenStudy (dan815):

if both not 0 then 13 is prime?

ganeshie8 (ganeshie8):

yup !

OpenStudy (dan815):

okay this looks like a good idea

OpenStudy (dan815):

can you think of anything more efficient than this

OpenStudy (dan815):

i will write up that program meanwhile brb

ganeshie8 (ganeshie8):

nope, this is also called seive of eratosthenes or something...

OpenStudy (dan815):

cool

ganeshie8 (ganeshie8):

good luck wid the program :)

OpenStudy (dan815):

you know python btw ganeshi?

ganeshie8 (ganeshie8):

i can understand python but im good wid perl

OpenStudy (dan815):

oh ive seen this langueage

OpenStudy (dan815):

i didnt know it was popular

ganeshie8 (ganeshie8):

python is popular in academics area perl is popular in work place

ganeshie8 (ganeshie8):

both we use...

OpenStudy (dan815):

how about matlab

ganeshie8 (ganeshie8):

we dont use matlab much, we have other simulation software

OpenStudy (dan815):

i feel like matlab is really good for all the math stuff, but im not that fluent yet at manipulating matrices

OpenStudy (dan815):

so i stick to writing on python for now

OpenStudy (dan815):

just getting used a new language takes a while

ganeshie8 (ganeshie8):

yah. its like, u will be using python for preparing input to matlab... cuz in python manipulating data is easy

OpenStudy (dan815):

@ganeshi8 i think my code is really bad or something lol it takes a while for this to excecute

OpenStudy (dan815):

@ganeshie8

ganeshie8 (ganeshie8):

show me the code...

OpenStudy (dan815):

y=[2] for i in range(1,60000): a=2*i+1 b=round(a**0.5) count=0 for j in y: if j<b: if a%j!=0: count=count else: count=count+1 if count==0: y.append(a)

OpenStudy (dan815):

y[10000] doest seem to be giving me the 10 001st prime either hmm

OpenStudy (dan815):

some funky stuff going on i checked the numbers im getting any it seems like they are all prime numbers but some of the numbers are missing or something

OpenStudy (dan815):

y[1001] = 7723

ganeshie8 (ganeshie8):

what below line is doing ? a=2*i+1

OpenStudy (dan815):

but from this chart is the 980th prime http://www.sosmath.com/tables/prime/prime.html

OpenStudy (dan815):

rounding

OpenStudy (dan815):

let me get rid of that round

ganeshie8 (ganeshie8):

OpenStudy (dan815):

yeah

ganeshie8 (ganeshie8):

i asked it for primes less than 10 why it is throwing out 11, 13, 17, 19 ?

OpenStudy (dan815):

no for 10

OpenStudy (dan815):

you are looking at all the odd numbers till 21

ganeshie8 (ganeshie8):

yeah, why ?

OpenStudy (dan815):

i dunno lol i just coded it that way

OpenStudy (dan815):

i wanted to just enter some numbers to get atleast 10000 primes

ganeshie8 (ganeshie8):

oh, thats intentional is it... okay :) but it seem ot be working fine

OpenStudy (dan815):

but something is wrong i dunno if there are some reapting primes in there or somethjing

OpenStudy (dan815):

because when i do y[10000] im not getting the right answer

OpenStudy (dan815):

or when im doing y[1000] its really only giving me the 980th prime

ganeshie8 (ganeshie8):

okay, let me have a good look at the code again

OpenStudy (dan815):

i took of the round maybe this fixes it let me see

OpenStudy (dan815):

nope still getting 104021

ganeshie8 (ganeshie8):

found the issue

OpenStudy (dan815):

whats wrong with it

ganeshie8 (ganeshie8):

try this :- y=[2] for i in range(1,50): a=2*i+1 b=round(a**0.5) count=0 for j in y: if j<=b: if a%j!=0: count=count else: count=count+1 if count==0: y.append(a) print y

ganeshie8 (ganeshie8):

if \(n\) is not a prime , there will be atleast one prime factor \(<\color{red}{=} \sqrt{n}\)

ganeshie8 (ganeshie8):

lol i gave u incorrect info before :|

OpenStudy (dan815):

this is fine that wont change my code i think

OpenStudy (dan815):

just really weird how can there be extra numbers popping up

OpenStudy (dan815):

some of them must not be primes in there but wheres that mistake coming from

ganeshie8 (ganeshie8):

that changes everything

OpenStudy (dan815):

oh

ganeshie8 (ganeshie8):

if u dont put that equal sign, 49 is also a prime according to ur code.

OpenStudy (dan815):

ohhh I see!!

ganeshie8 (ganeshie8):

ur code wont check the prime factor 7, for 49

OpenStudy (dan815):

i seee i seeeeeee

OpenStudy (dan815):

<3

ganeshie8 (ganeshie8):

cool :)

OpenStudy (dan815):

i thought i already had hte equal there

OpenStudy (dan815):

hard to notice these changes lol

ganeshie8 (ganeshie8):

yahh how much time its taking when u iterate ofr 60000 ?

OpenStudy (dan815):

sweet its right

OpenStudy (dan815):

like 15 secs

OpenStudy (dan815):

gives me about 11301 primes for 60000

OpenStudy (dan815):

man.. finding primes must be some advanced math.. i wonder what kind of algorithms they use to find those huge primes

OpenStudy (dan815):

for every aditional digit in my range my time is going up exponentially or cubing

ganeshie8 (ganeshie8):

yeah primes get rarer and rarer...

OpenStudy (dan815):

after you solve it it gives you their method, usually the most efficient method u wanna see it?

ganeshie8 (ganeshie8):

yesss

OpenStudy (dan815):

they actually did do something we did, this makes me happy

ganeshie8 (ganeshie8):

but i dont think it wil be any different from your method :o

OpenStudy (dan815):

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!