题目描述
分解质因数Prime factor(Primefac)
【问题】求正整数n的质因子,输出如下形式: 100=2*2*5*5
【输入】一个<=100000的正整数n
【输出】按题目要求的形式输出n的质因子
【问题】求正整数n的质因子,输出如下形式: 100=2*2*5*5
【输入】一个<=100000的正整数n
【输出】按题目要求的形式输出n的质因子
输入
输出
样例输入
样例输出
Const
max=32000;
var a:array[2..max]of boolean;
p:array[1..3500]of word;
i,j,m:word;l:longint;
begin
for i:=2 to max do
a[i]:=true;j:=0;
for i:=2 to trunc(sqrt(max)) do
if a[i] then
begin
m:=i;
repeat
inc(m,i);
if m<=max then a[m]:=false
until m>max
end;
for i:=2 to max do
if a[i] then
begin
inc(j);p[j]:=i
end;
//for i:=2 to j do write(p[i]:8)
readln(l);
write(l,'=');
if l>0 then
repeat
for i:=1 to j do if l mod p[i]=0 then
begin l:=l div p[i];
write(p[i]);if l>1 then
write('*');
break;
end;
until (l=1)or(i=j);
if i=j then write(l);
writeln
end.