var i:integer;
begin
for i:=1 to 999 do
if (i mod 3=0)and
((i mod 10=5) or (i div 10 mod 10=5) or (i div 100=5))
then write(i:10);
end.
前面复杂度为O(999),其实可以再快一点:
program div;
var i1,i2:integer;
begin
for i:=1 to 333 do
begin
i2:=3*i;
if (i2 div 100=5) or ((i2-(i2 div 100 * 100)) mod 10=5) or (i2 mod 10=5) then write(i2:5):
end;
readln;
end.
var s:string;
i,j:integer;
begin
for i:=1 to 999 do
if i mod 3=0 then
begin
str(i,s);
for j:=1 to 3 do
if s[j]='5' then
writeln(i);
end;
end.
var i1,i2:integer;
begin
for i:=1 to 333 do
begin
i2:=3*i;
if (i2 div 100=5) or ((i2-(i2 div 100 * 100)) mod 10=5) or (i2 mod 10=5) then write(i2:5):
end;
readln;
end.