-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactorise.py
More file actions
28 lines (25 loc) · 776 Bytes
/
factorise.py
File metadata and controls
28 lines (25 loc) · 776 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 26 13:45:02 2018
@author: edwin
"""
def factorise(number,factorArray):
import math
if (number == 1):
return factorArray
if factorArray:
if (number%(factorArray[-1][0]) == 0):
factorArray[-1][1] = factorArray[-1][1] + 1
return factorise(number//factorArray[-1][0],factorArray)
lowerBound = 2
if factorArray:
lowerBound = factorArray[-1][0] + 1
for i in range(lowerBound,1 + math.floor(math.sqrt(number))):
if (number%i == 0):
factorArray.append([i,1])
return factorise(number//i, factorArray)
factorArray.append([number,1])
return factorArray
def main(number):
return factorise(number,[])