pascal 循环结构 分解质因数

2024-11-22 00:52:52
推荐回答(2个)
回答1:

var
i,j,k,n:longint;
begin
readln(n);
write(n,'=');
i:=1;
repeat
inc(i);k:=0;
while n mod i=0 do
begin
n:=n div i;
inc(k);
end;
if (k>0)and(i<>2) then write('*');
if k>0 then write(i);
for j:=2 to k do write('*',i);
until n=1;
end.

回答2:

1s 穷举法,也不会超过吧!