求一个pascal程序?

来源:百度知道 编辑:UC知道 时间:2024/05/10 13:53:33
1.求丑数(UGLY)
源程序名 ugly.??? (PAS,C,CPP)
可执行文件名 ugly.EXE
输入文件名 ugly.IN
输出文件名 ugly.OUT
所谓丑数,就是指那些因子只含2,3,5的数。1,2,3,4,5,6,8,9,10,12,15是最前面的11个丑数。为了方便起见,把1也看作是丑数。
请你编写一个程序,输入n,n<3000,寻找并打印第n个丑数。
样例输入:
11
样例输出:
15

var
temp,n,tot:int64;
i,j,k:longint;
a:array[0..3000]of boolean;
begin
fillchar(a,sizeof(a),false);
for i:=0 to 11 do
for j:=0 to 7 do
for k:=0 to 4 do
begin
temp:=(2**i)*(3**j)*(5**k);
if temp<=3000
then a[temp]:=true;
end;
a[1]:=true;
readln(n);
tot:=0;
for i:=1 to 3000 do
begin
if a[i]=true then inc(tot);
if tot=n then begin
writeln(i); break; end;
end;
end.