Either I don't understand, or you're having a hard time:import random
n = int(input("Введите значение n: "))
m = int(input("Введите значение m: "))
array = []
for i in range(n):
row=[]
for j in range(m):
row.append(random.randint(-1,5))
array.append(row)
print("Матрица:",array)
q5=int(input("Введите заданное число: "))
for i in range(n):
for j in range(m):
if array[i][j]%q5==0:
print(array[i][j],i,j,int(array[i][j]/q5))
Результат:
Введите значение n: 6
Введите значение m: 8
Матрица: [[4, -1, 4, 3, -1, 2, 0, 3], [4, 1, 4, 0, 2, 4, -1, 1], [1, 4, 5, 4,
3, 1, 5, 1], [1, -1, 5, 5, 3, 4, 4, 1], [2, 3, 3, 4, -1, 1, 4, 0], [5, -1, 2,
1, -1, 2, 1, 0]]
Введите заданное число: 2
4 0 0 2
4 0 2 2
2 0 5 1
0 0 6 0
4 1 0 2
4 1 2 2
0 1 3 0
2 1 4 1
4 1 5 2
4 2 1 2
4 2 3 2
4 3 5 2
4 3 6 2
2 4 0 1
4 4 3 2
4 4 6 2
0 4 7 0
2 5 2 1
2 5 5 1
0 5 7 0
And, yes, of course, 0 is counted as multiple to any number. If not, replace the last condition witharray[i][j]!=0 and array[i][j]%q5==0:
Supplement.Since the answer appears to be difficult to understand the TC, bringing it to a super-simplistic version, answering the question, "if I hit q5 10, it should find 30 or 100 in the matrix, for example." I hope it is now clear that the first answer does not change the matrix, which is what you described:array= [[40, -10, 4, 30],[20,3,100,5],[10,20,30,3],[3,3,20,3]]
q5=int(input("Введите заданное число: "))
for i in range(len(array)):
for j in range(len(array[0])):
if array[i][j]%q5==0:
print(array[i][j],int(array[i][j]/q5))
Result: Введите заданное число: 10
40 4
-10 -1
30 3
20 2
100 10
10 1
20 2
30 3
20 2