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

please tell me why my program got wA??? i think that it is correct!
Posted by artem 6 Aug 2004 20:38
var n:longint;
    i,j:byte;
    a:array[2..9] of byte;
begin
  fillchar(a,sizeof(a),0);
  readln(n);
  if (n=1) then begin writeln('1');halt end;
  if (n=0) then begin writeln('10');halt end;
  while ((n mod 2)=0) do
  begin
    a[2]:=a[2]+1;
    n:=n div 2;
  end;

  while ((n mod 3)=0) do
  begin
    a[3]:=a[3]+1;
    n:=n div 3;
  end;

  while ((n mod 5)=0) do
  begin
    a[5]:=a[5]+1;
    n:=n div 5;
  end;

  while ((n mod 7)=0) do
  begin
    a[7]:=a[7]+1;
    n:=n div 7;
  end;
  if (n<>1) then writeln('-1')
  else
  begin
    a[8]:=a[2] div 3;
    a[2]:=a[2] - a[8]*3;
    a[9]:=a[3] div 2;
    a[3]:=a[3] - a[9]*2;
    if ((a[2]=2) and (a[3]=1)) then
    begin
      a[6]:=a[6]+1;
      a[2]:=a[2]-1;
      a[3]:=a[3]-1
    end
    else if ((a[2]=1) and (a[3]=1)) then
    begin
      a[6]:=a[6]+1;
      a[2]:=a[2]-1;
      a[3]:=a[3]-1
    end
    else if ((a[2]=2) and (a[3]=0)) then
    begin
      a[4]:=a[4]+1;
      a[2]:=a[2]-2;
    end
  end;
  for i:=2 to 9 do for j:=1 to a[i] do write(i);
  writeln;
end.
Re: please tell me why my program got wA??? i think that it is correct!
Posted by Alatau 6 Aug 2004 22:31
you must start with
  n mod 9
then
  n mod 8
then
  n mod 7
...
  n mod 2