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

Help, please! Why WA??? (code inside)
Posted by ValBG 9 Apr 2002 02:01
I just can't see my mistake! I have considered the zero and 1..9
cases, and output -1 for numbers that have a prime divisor greater
that 7, but it's stil WA ???

 Program Digits_Product(input,output);
 Var N,i,j,k:longint;
     A:array[1..4]of 2..7;
     B:array[1..255]of word;
     Q:string;

 Procedure Sort(k:longint);
    var i,j:byte;
        p:word;
    begin
      for i:=1 to K-1 do
        for j:=i+1 to K do
          if B[i]>B[j] then
            begin
              p:=B[i];
              B[i]:=B[j];
              B[j]:=p
            end
    end;

 Begin
   readln(N);
   for i:=1 to 255 do B[i]:=1;
   A[1]:=2;
   A[2]:=3;
   A[3]:=5;
   A[4]:=7;
   case N of
        0:begin writeln(10); halt end;
     1..9:begin writeln(N); halt end
     else Q:='-1';
   end;
   i:=1;
   for j:=1 to 4 do
     while N mod A[j]=0 do
       begin
         B[i]:=A[j];
         N:=N div A[j];
         i:=i+1
       end;
   if N<>1 then
     begin
       writeln(Q);
       halt
     end;
   k:=i;
   for i:=1 to k-1 do
     for j:=i+1 to k do
        if B[i]*B[j]<=9 then
           begin
             B[i]:=B[i]*B[j];
             B[j]:=1;
           end;
   Sort(k);
   Q:='';
   for i:=1 to k do
      if B[i]<>1 then Insert(chr(B[i]+48),Q,length(q)+1);
   writeln(Q);
 End.