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