主题:[急救]请问,这道题如何用数学思想解决?
1.program program2;
var
i, number, ndata, sum: integer;
data: array[1..100] of integer;
procedure solve(s, sign, n: integer);
var i: integer;
begin
for i := s to ndata do begin
inc(sum, sign * (number div (n * data[i])));
solve(i + 1, -sign, n * data[i]);
end;
end;
begin
read(number ,ndata);
sum := 0;
for i := 1 to ndata do read(data[i]);
solve(1, 1, 1);
writeln(sum);
end.
输入:1000 3 5 13 11
输出:328
var
i, number, ndata, sum: integer;
data: array[1..100] of integer;
procedure solve(s, sign, n: integer);
var i: integer;
begin
for i := s to ndata do begin
inc(sum, sign * (number div (n * data[i])));
solve(i + 1, -sign, n * data[i]);
end;
end;
begin
read(number ,ndata);
sum := 0;
for i := 1 to ndata do read(data[i]);
solve(1, 1, 1);
writeln(sum);
end.
输入:1000 3 5 13 11
输出:328