-3

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)
Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55
sarvesh kumar
  • 183
  • 11

1 Answers1

2

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.

Noah
  • 430
  • 1
  • 4
  • 21
  • 1
    @EcSync He never specified it was an assignment, and if he had just googled "find multiples of number python" then he would have found the exact same thing I found. I don't believe that me linking that was bad, him using it improperly would be bad though. – Noah Oct 29 '19 at 17:24