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
dd771dec
Commit
dd771dec
authored
Nov 30, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
herp
parent
9547fad4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
35 deletions
+45
-35
problem243.py
problem243.py
+20
-35
problem381.py
problem381.py
+25
-0
No files found.
problem243.py
View file @
dd771dec
#!/usr/bin/env python
#!/usr/bin/env python
from
__future__
import
division
from
__future__
import
division
from
math
import
sqrt
,
ceil
from
primes
import
is_prime
,
nprimes
def
primes_until
(
n
):
print
list
(
nprimes
(
15499
))
""" Sieve of Eratosthenes """
import
sys
;
sys
.
exit
()
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
times
(
a
,
b
):
def
times
(
a
,
b
):
return
a
*
b
return
a
*
b
def
div
(
m
,
n
):
known_primes
=
{}
return
not
divmod
(
n
,
m
)[
1
]
MAX
=
2000000
all_primes
=
list
(
primes_until
(
MAX
))
def
primes
(
n
):
def
primes
(
n
):
for
p
in
all_primes
:
for
p
in
range
(
2
,
n
):
if
p
>=
n
:
if
p
in
known_primes
:
raise
StopIteration
yield
p
elif
is_prime
(
p
):
known_primes
[
p
]
=
None
yield
p
yield
p
def
phi
(
n
):
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
):
def
resilience
(
d
):
return
phi
(
d
)
/
(
d
-
1
)
return
phi
(
d
)
/
(
d
-
1
)
d
=
2
d
=
30
while
True
:
print
d
,
try
:
res
=
resilience
(
d
)
while
resilience
(
d
)
>=
15499
/
94744
:
d
+=
1
if
d
==
MAX
:
if
res
<
15499
/
94744
:
print
'maximum reached:'
,
break
break
except
KeyboardInterrupt
:
print
'interrupted:'
,
print
d
print
res
,
15499
/
94744
d
+=
30
problem381.py
0 → 100644
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
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