in ps1 i can generate primes but the problem with output is that it is painfully repetitive. the code is here http://codepad.org/9ZdIo1Cv suggestions and modifications required...... the output is like: 2 2 3 2 3 5 2 3 5 7 ......so on
what output do you want? do you want to calculate all primes from 0 to n for a given input n?
i want that output should not be repetitive as it is above. it should be continuous like 2 3 5 7 11 .....and so on
def primes(n): s=range(0,n+1) s[1]=0 bottom=2 top=n//bottom while (bottom*bottom<=n): while (bottom<=top): if s[top]: s[top*bottom]=0 top-=1 bottom+=1 top=n//bottom return [x for x in s if x] Try that? print primes(131)
Join our real-time social learning platform and learn together with your friends!