ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1014. Product of Digits

Why Time limit Exided
Posted by misha 23 Oct 2002 11:07
program zzz;
var n,l,i,j,k : longint;
    q : real;
    s : string;
    a : array [1..100000] of byte;
begin
   read(n);
   k := 0;
   if n = 0 then begin
      write(0);
      halt;
   end;
   while true do begin
      for i := 9 downto 2 do begin
         if n mod i = 0 then begin
            k := k+1;
            a[k] := i;
            n := n div i;
            break;
         end;
      end;
      if (n < 10) then begin
         if n > 1 then begin
            k := k+1;
            a[k] := n;
         end;
         break;
      end;
      if i = 2 then begin
         write(-1);
         halt;
      end;
   end;
   for i := 1 to k-1 do begin
      for j:= i+1 to k do begin
         if a[i]>a[j] then begin
            l := a[i];
            a[i] := a[j];
            a[j] := l;
         end;
      end;
   end;
   if k = 0 then write(1);
   for i := 1 to k do begin
      write(a[i]);
   end;
end.
Re: Why Time limit Exided
Posted by Oleg 24 Oct 2002 14:45
> program zzz;
> var n,l,i,j,k : longint;
>     q : real;
>     s : string;
>     a : array [1..100000] of byte;
> begin
>    read(n);
>    k := 0;
>    if n = 0 then begin
>       write(0);
>       halt;
>    end;
>    while true do begin
>       for i := 9 downto 2 do begin
>          if n mod i = 0 then begin
>             k := k+1;
>             a[k] := i;
>             n := n div i;
>             break;
>          end;
>       end;
>       if (n < 10) then begin
>          if n > 1 then begin
>             k := k+1;
>             a[k] := n;
>          end;
>          break;
>       end;
>       if i = 2 then begin
>          write(-1);
>          halt;
>       end;
>    end;
>    for i := 1 to k-1 do begin
>       for j:= i+1 to k do begin
>          if a[i]>a[j] then begin
>             l := a[i];
>             a[i] := a[j];
>             a[j] := l;
>          end;
>       end;
>    end;
>    if k = 0 then write(1);
>    for i := 1 to k do begin
>       write(a[i]);
>    end;
> end.

LHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLHLH