1.
var
a, b: integer;
function work(a, b: integer): integer;
begin
if a mod b <> 0 then
work := work(b, a mod b)
else
work := b;
end;
begin
read(a, b);
writeln(work(a, b));
end.
输入:123 321
输出:3
2.
var
a, b: array[0..3] of integer;
i, j, tmp: integer;
begin
for i := 0 to 3 do
read(b[i]);
for i := 0 to 3 do
begin
a[i] := 0;
for j := 0 to i do
begin
inc(a[i], b[j]);
inc(b[a[i] mod 4], a[j]);
end;
end;
tmp := 1;
for i := 0 to 3 do
begin a[i] := a[i] mod 10;
b[i] := b[i] mod 10;
tmp := tmp * (a[i] + b[i]);
end;
writeln(tmp);
end.
输入:2 3 5 7
输出:5850
3.
const
y = 2009;
maxn = 50;
var
n, i, j, s: longint;
c: array[0..maxn, 0..maxn] of longint;
begin
s := 0;
read(n);
c[0, 0] := 1;
for i := 1 to n do
begin
c[i, 0] := 1;
for j := 1 to i - 1 do
c[i, j] := c[i-1, j-1] + c[i-1, j];
c[i, i] := 1;
end;
for i := 0 to n do
s := (s + c[n, i]) mod y;
write(s);
end.
输入:17
输出:487
4.
var
n, m, i, j, k, p: integer;
a, b: array[0..100] of integer;
begin
read(n, m);
a[0] := n;
i := 0;
p := 0;
k := 0;
repeat
for j := 0 to i - 1 do
if a[i] = a[j] then
begin
p := 1;
k := j;
break;
end;
if p <> 0 then
break;
b[i] := a[i] div m;
a[i+1] := (a[i] mod m) * 10;
inc(i);
until a[i] = 0;
write(b[0], '.');
for j := 1 to k - 1 do
write(b[j]);
if p <> 0 then
write('(');
for j := k to i - 1 do
write(b[j]);
if p <> 0 then
write(')');
writeln;
end.
输入:5 13
输出:0.(384615)