N tourists have a backpack with canned food. How many, at least, canned food must be removed from the bag

N tourists have a backpack with canned food. How many, at least, canned food must be removed from the bag so that the rest are divided equally among all the tourists. You need to enter the amount of canned food and the number of tourists into the program.

Program turisti_i_conservi;
var n, k, rez, z: integer; /// all variables are integer
begin
rez: = 0;
writeln (‘Enter the number of tourists’);
readln (n);
writeln (‘Enter the amount of canned food’);
readln (k);
z: = k; /// initial amount of canned food = z
while (k mod n <> 0) do /// until the amount of canned food is divided without a remainder by the number of tourists, execute
k: = k – 1; /// subtract one canned food
rez: = z – k; /// the difference between the initial amount of canned food and the remainder after performing the above action
writeln (rez); /// result
end.

Tested in PascalABC



One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.