To find the multiple of the number I am using two inners for loop which is o(n*n) complexity, is there any other way to find multiples with optimized way..
Example :
- 50 multiples are (5,10)
- 42 multiples are (7,6)
- 168 multiples are (12,14)
To find the multiple of the number I am using two inners for loop which is o(n*n) complexity, is there any other way to find multiples with optimized way..
Example :
The multiples of a number are that number multiplied by any other integer. The factors of a number are the numbers that when multiplied the product is that number. It seems like you are looking for the factors because the factors of 50 are 5,10,2,25, etc. There is a great tutorial here which can help you out. I think that you should problem solve on your own but here is the code that they used for the example.
# Python Program to find the factors of a number
# define a function
def print_factors(x):
# This function takes a number and prints the factors
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
# change this value for a different result.
num = 320
# uncomment the following line to take input from the user
#num = int(input("Enter a number: "))
print_factors(num)
good luck on the rest of your assignment.