-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp047.py
More file actions
executable file
·45 lines (37 loc) · 974 Bytes
/
p047.py
File metadata and controls
executable file
·45 lines (37 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#The first two consecutive numbers to have two distinct prime factors are:
#
#14 = 2 x 7
#15 = 3 x 5
#
#The first three consecutive numbers to have three distinct prime factors are:
#
#644 = 2^2 x 7 x 23
#645 = 3 x 5 x 43
#646 = 2 x 17 x 19.
#
#Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers?
import logging
from prime import PrimeNumberPool
def defactor(n, prime):
f = set()
if (prime.IsPrime(n)):
return f
for p in prime.numbers:
if (p >n):
return f
while (n % p == 0):
f.add(p)
n = n//p
if (n>1):
f.add(n)
return f
def main(args):
if args.test:
n = 100
else:
n = 647
prime = PrimeNumberPool()
while (len(defactor(n, prime)) < 4 or len(defactor(n+1, prime)) < 4 or
len(defactor(n+2, prime)) < 4 or len(defactor(n+3, prime)) < 4):
n += 1
logging.info(n)