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
wait ok no forget that!! start over
to test if 'n' is a prime :- you need to test all the prime numbers < sqrt(n)
this is more of a math/ computer algorithm question, need to find efficient ways of adding primes to list
yeah ganeishi but just
i realized 13 wasnt given it was found so, what would you suggest best way if you just must find the prime too
there will be primes that differ by 2 : (11, 13), (17, 19)
so, we need to test each and every ODD number
is there better way, that is lots of function time
let me get this clear :- you're saying testing for prime factors < sqrt(n) is a lot of function time ?
no
n is not given
oh, basically u want to create list of all prime number ?
yeah
@mukushla is here :)
but i see what u are suggesting that is not a bad way to go about it too
take every odd number sqrt it and keep checking permutations of our existing prime list?
nope. just check if a 'single' prime factor exists thats less than sqrt of it
ok so say for 13
if \(n\) is not a prime , there will be atleast one prime factor < \(\sqrt{n}\)
id do 13 mod 2 13 mod 3
if both not 0 then 13 is prime?
yup !
okay this looks like a good idea
can you think of anything more efficient than this
i will write up that program meanwhile brb
nope, this is also called seive of eratosthenes or something...
cool
good luck wid the program :)
you know python btw ganeshi?
i can understand python but im good wid perl
oh ive seen this langueage
i didnt know it was popular
python is popular in academics area perl is popular in work place
both we use...
how about matlab
we dont use matlab much, we have other simulation software
i feel like matlab is really good for all the math stuff, but im not that fluent yet at manipulating matrices
so i stick to writing on python for now
just getting used a new language takes a while
yah. its like, u will be using python for preparing input to matlab... cuz in python manipulating data is easy
@ganeshi8 i think my code is really bad or something lol it takes a while for this to excecute
@ganeshie8
show me the code...
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)
y[10000] doest seem to be giving me the 10 001st prime either hmm
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
y[1001] = 7723
what below line is doing ? a=2*i+1
but from this chart is the 980th prime http://www.sosmath.com/tables/prime/prime.html
rounding
let me get rid of that round
yeah
i asked it for primes less than 10 why it is throwing out 11, 13, 17, 19 ?
no for 10
you are looking at all the odd numbers till 21
yeah, why ?
i dunno lol i just coded it that way
i wanted to just enter some numbers to get atleast 10000 primes
oh, thats intentional is it... okay :) but it seem ot be working fine
but something is wrong i dunno if there are some reapting primes in there or somethjing
because when i do y[10000] im not getting the right answer
or when im doing y[1000] its really only giving me the 980th prime
okay, let me have a good look at the code again
i took of the round maybe this fixes it let me see
nope still getting 104021
found the issue
whats wrong with it
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
if \(n\) is not a prime , there will be atleast one prime factor \(<\color{red}{=} \sqrt{n}\)
lol i gave u incorrect info before :|
this is fine that wont change my code i think
just really weird how can there be extra numbers popping up
some of them must not be primes in there but wheres that mistake coming from
that changes everything
oh
if u dont put that equal sign, 49 is also a prime according to ur code.
ohhh I see!!
ur code wont check the prime factor 7, for 49
i seee i seeeeeee
<3
cool :)
i thought i already had hte equal there
hard to notice these changes lol
yahh how much time its taking when u iterate ofr 60000 ?
sweet its right
like 15 secs
gives me about 11301 primes for 60000
man.. finding primes must be some advanced math.. i wonder what kind of algorithms they use to find those huge primes
for every aditional digit in my range my time is going up exponentially or cubing
yeah primes get rarer and rarer...
after you solve it it gives you their method, usually the most efficient method u wanna see it?
yesss
they actually did do something we did, this makes me happy
but i dont think it wil be any different from your method :o
Join our real-time social learning platform and learn together with your friends!