Answer the question
In order to leave comments, you need to log in
Is it possible to solve this, make a formula/algorithm?
Problem about monks
There are 3 groups of monks: leading, simple, students. M monks eat N pies by order.
Leader in N1 pies, simple in N2 pies, students in N3 pies (N, N1, N2, N3 - can be whole and fractional numbers).
How many monks were: leading (M1), simple (M2) and disciples (M3).
Input data
M - number of monks in total
N - number of pies in total
N1 - number of pies eaten by one leading monk
N2 - number of pies eaten by one simple monk
N2 - number of pies eaten by one student monk
Results
M1 - number of leading monks
M2 - number of simple monks
M3 - the number of monks-apprentices
Answer the question
In order to leave comments, you need to log in
Для каждого M1 от 0 до N/N1
M2 = (N - M1*N1 -M*N3 + M1*N3) / (N2 - N3)
M3 = M - M1 - M2
если M2 целое число и М3>0
то вернуть ответ М1, М2, М3
In this form, it is impossible to solve, since the condition does not say how the output data depends on the input. And it is not specified what the variables M and P mean.
It is possible with two nested loops - we sort through M1 and M2, and M3 is found from the system of equations.
M1 + M2 + M3 = M
M1*P1 + M2*P2 + M3*P3 = P
here the question is in the condition, if you read literally, then the system of equations is as follows:
N = N1*M1 + N2*M2 +N3*M3
M = M1 + M2 + M3
M1>=0
M2>=0
M3>=0
obviously - it can be solve, but there can be more than 1 solution
trivial algorithm - enumeration of all possible M1,M2,M3
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question