-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsmallestMultiple.py
More file actions
51 lines (41 loc) · 1.2 KB
/
smallestMultiple.py
File metadata and controls
51 lines (41 loc) · 1.2 KB
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
46
47
48
49
50
51
import math
import copy
# A function to print all prime factors of
# a given number n
def primeFactors(n):
allPrimeFactors = [1]
temp = n
# Print the number of two's that divide n
while n % 2 == 0:
allPrimeFactors.append(2)
n = n // 2
# n must be odd at this point
# so a skip of 2 ( i = i + 2) can be used
for i in range(3,n+1,2):
# while i divides n , print i ad divide n
while n % i== 0:
allPrimeFactors.append(i)
n = n // i
# Condition if n is a prime
if len(allPrimeFactors) == 1:
allPrimeFactors.append(temp)
# number greater than 2
return allPrimeFactors
# print(primeFactors(17))
def smallestMultiple(n):
factors = []
for i in range(3, n+1):
temp = copy.deepcopy(factors)
currfactors = primeFactors(i)
print(currfactors)
print(temp)
for i in currfactors:
if i in temp:
print(i)
temp.remove(i)
currfactors.remove(i)
for i in currfactors:
factors.append(i)
return factors
print(smallestMultiple(10))
print("Program ends")