Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
projecteuler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
projecteuler
Commits
dd771dec
Commit
dd771dec
authored
12 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
herp
parent
9547fad4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
problem243.py
+20
-35
20 additions, 35 deletions
problem243.py
problem381.py
+25
-0
25 additions, 0 deletions
problem381.py
with
45 additions
and
35 deletions
problem243.py
+
20
−
35
View file @
dd771dec
#!/usr/bin/env python
from
__future__
import
division
from
math
import
sqrt
,
ceil
from
primes
import
is_prime
,
nprimes
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
print
list
(
nprimes
(
15499
))
import
sys
;
sys
.
exit
()
def
times
(
a
,
b
):
return
a
*
b
def
div
(
m
,
n
):
return
not
divmod
(
n
,
m
)[
1
]
MAX
=
2000000
all_primes
=
list
(
primes_until
(
MAX
))
known_primes
=
{}
def
primes
(
n
):
for
p
in
all_primes
:
if
p
>=
n
:
raise
StopIteration
yield
p
for
p
in
range
(
2
,
n
):
if
p
in
known_primes
:
yield
p
elif
is_prime
(
p
):
known_primes
[
p
]
=
None
yield
p
def
phi
(
n
):
return
reduce
(
times
,
iter
(
1
-
1
/
p
for
p
in
primes
(
n
)
if
div
(
p
,
n
)
),
n
)
return
reduce
(
times
,
iter
(
1
-
1
/
p
for
p
in
primes
(
n
)
if
not
n
%
p
),
n
)
def
resilience
(
d
):
return
phi
(
d
)
/
(
d
-
1
)
d
=
2
d
=
30
while
True
:
print
d
,
try
:
while
resilience
(
d
)
>=
15499
/
94744
:
d
+=
1
res
=
resilience
(
d
)
if
d
==
MAX
:
print
'
maximum reached:
'
,
break
except
KeyboardInterrupt
:
print
'
interrupted:
'
,
if
res
<
15499
/
94744
:
break
print
d
print
res
,
15499
/
94744
d
+=
30
This diff is collapsed.
Click to expand it.
problem381.py
0 → 100644
+
25
−
0
View file @
dd771dec
#!/usr/bin/env python
from
math
import
gamma
,
factorial
def
S
(
p
):
return
sum
(
factorial
(
p
-
k
)
for
k
in
range
(
1
,
6
))
%
p
def
modfac
(,
p
)
facs
=
[
factorial
(
p
)
for
p
in
range
(
5
)]
total
=
s
=
S
(
5
)
pmin6fac
=
0
pmin1fac
=
factorial
(
5
)
print
5
,
S
(
5
)
N
=
100
facs
=
[
factorial
(
p
)
%
p
for
p
in
range
(
5
)]
for
p
in
xrange
(
6
,
1000000
):
s
=
s
-
pmin6fac
+
pmin1fac
total
+=
s
%
p
if
s
:
print
p
,
s
%
p
pmin6fac
*=
p
-
5
pmin1fac
*=
p
print
total
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment