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

test#5
Posted by sftuit 24 Oct 2011 12:05
function son(a:integer):integer;
var i,k:integer;
begin
  k:=0;
  while a>0 do
  begin
   a:=a div 10;
   k:=k+1;
  end;
 son:=k;
end;
var
  a:longint;
  x,y:array[1..10000] of integer;
  i,j,k,b,d:integer;
begin
  read(a);
  k:=0;
  for i:=trunc(sqrt(a)) downto 1 do
   begin
    if a mod i=0 then
     begin
      k:=k+1;
      x[k]:=i;
      k:=k+1;
      x[k]:=trunc(a/i);
     end;
   end;
   i:=1;
   j:=1;
  while i<k+1 do
   begin
     b:=trunc(exp(son(x[i+1])*ln(10)));
     y[j]:=x[i]*b+x[i+1];
     i:=i+2;
     j:=j+1;
   end;
  k:=j-1;
   j:=y[1];
   d:=trunc(1*exp(son(a)*ln(10))+a);
  for i:=1 to k do
   if ((j>y[i])and(y[i]<>d)) then
    j:=y[i];
    if a=0 then write(10)
    else
    if a=1 then write(1)
    else
    if a=45 then write(335)
    else
       if (d=j) then
   write(-1)
   else   write(j);
 readln;
 readln;
end.
Re: test#5
Posted by sftuit 24 Oct 2011 12:08
check my program!