-
Notifications
You must be signed in to change notification settings - Fork 1
/
deloitte_04.py
46 lines (35 loc) · 1.11 KB
/
deloitte_04.py
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
import numpy as np
def primes_up_to_root(n):
numbers = np.arange(3,int(np.sqrt(n))+1,2)
length = len(numbers)
for i in xrange(length):
a = numbers[i]
if (not a):
continue
else:
numbers[np.arange(a/2-1+a,length,a)] = 0
numbers = numbers[np.where(numbers)]
numbers = np.insert(numbers,0,2)
return numbers
def factorise(n,primes):
factors = []
while (n>1):
for p in primes:
if (n%p==0):
factors.append(p)
n /= p
break
return factors
first_number_to_factorise = 379065191139531
next_numbers_to_factorise = [35432488, 806095675586097, 7405814774826, 379065191139531]
max_number_to_factorise = max([first_number_to_factorise]+next_numbers_to_factorise)
primes = primes_up_to_root(max_number_to_factorise)
factors = factorise(first_number_to_factorise,primes)
print first_number_to_factorise
print factors, "\n"
target_factors = []
for n in next_numbers_to_factorise:
factors = factorise(n,primes)
target_factors.append(factors)
print n
print factors, "\n"