|
|
back to boardWhy am I wrong??? Here's my program. I use greedy method. Program ural_1014; Const Infile =''; Outfile =''; Type Tproduct =array[2..9]of longint; Tnum =array[2..9]of longint; Var n :longint; fj :Tproduct; q :Tnum; Procedure init; var i,j :longint; begin assign(input,Infile); reset(input); read(n); close(input); if n=0 then begin assign(output,Outfile); rewrite(output); writeln(10); close(output); halt; end; for i:=2 to 9 do begin fj[i]:=0; while n mod i=0 do begin inc(fj[i]); n:=n div i; end; end; if n>1 then begin assign(output,Outfile); rewrite(output); writeln('?'); close(output); halt; end; end; Procedure work; var i :longint; begin for i:=2 to 9 do q[i]:=0; while (fj[3]>=2) do begin inc(q[9]); dec(fj[3],2); end; while (fj[2]>=3) do begin inc(q[8]); dec(fj[2],3); end; while (fj[7]>=1) do begin inc(q[7]); dec(fj[7],1); end; while (fj[2]>=1)and(fj[3]>=1) do begin inc(q[6]); dec(fj[2],1); dec(fj[3],1); end; while (fj[5]>=1) do begin inc(q[5]); dec(fj[5],1); end; while (fj[2]>=2) do begin inc(q[4]); dec(fj[2],2); end; while (fj[3]>=1) do begin inc(q[3]); dec(fj[3],1); end; while (fj[2]>=1) do begin inc(q[2]); dec(fj[2],1); end; end; Procedure out; var i,j :longint; begin assign(output,Outfile); rewrite(output); for i:=2 to 9 do for j:=1 to q[i] do write(i); writeln; close(output); end; Begin init; work; out; End. |
|
|