15.A school is preparing a large square floor for its annual function. The floor has N tiles arranged in a single row. The teacher wants to divide these tiles into equal-sized groups without leaving any tile unused. For example, if there are 12 tiles, the teacher can make:
1 group of 12 tiles
2 groups of 6 tiles
3 groups of 4 tiles
4 groups of 3 tiles
6 groups of 2 tiles
12 groups of 1 tile
Write a Python program that takes the number of tiles N and finds all possible group sizes that can divide the tiles equally.
#All Divisors
no = 1029
div = 2
while div < no:
if no % div == 0:
print(div) #All Divisors
div+=1
OUTPUT:
3
7
21
49
147
343
#First Divisor
no = 1029
div = 2
while div < no:
if no % div == 0:
print(div)
break # first divisors
div+=1
OUTPUT:
3
#Last Divisor
no = 1029
div = 2
last_div = 0
while div < no:
if no % div == 0:
print(div)
last_div = div # stores the current last value
div+=1
print("last div:" ,last_div) # print the last divisor
OUTPUT:
3
7
21
49
147
343
last div: 343
# Two Digit Divisors
no = 1029
div = 10
while div < 100:
if no % div == 0:
print(div)
div+=1
OUTPUT:
21
49
# print first number from the output:
no = 1029
div = 10
while div < 100:
if no % div == 0:
print(div//10) #10ns place values from the output
div+=1
OUTPUT:
2
4
# print second number from the output:
no = 1029
div = 10
while div < 100:
if no % div == 0:
print(div % 10)
div+=1
OUTPUT:
1
9
# check 1s and 10s number from the output and print the greatest values:
[TBD]
Top comments (0)