Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projecteuler
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
projecteuler
Commits
af633381
Commit
af633381
authored
Nov 28, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some prime number util functions
parent
04b49530
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
primes.py
primes.py
+36
-0
No files found.
primes.py
0 → 100644
View file @
af633381
def
is_prime
(
n
):
if
n
==
2
:
return
True
if
n
<
2
or
not
n
&
1
:
return
False
for
i
in
xrange
(
3
,
int
(
n
**
.
5
)
+
1
,
2
):
if
not
n
%
i
:
return
False
return
True
def
primes_until
(
n
):
""" Sieve of Eratosthenes """
lst
=
[
False
]
*
n
i
=
2
while
i
<
n
:
if
not
lst
[
i
]:
yield
i
for
j
in
xrange
(
i
,
n
,
i
):
lst
[
j
]
=
True
i
+=
1
def
nprimes
(
n
):
a
=
2
while
n
:
if
is_prime
(
a
):
yield
a
n
-=
1
a
+=
1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment