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 I am Wrong,please help me.
Posted by Dick162 15 Jun 2002 15:05
program ex;
const
  maxn=20;
var
  i,n:longint;
  flag:boolean;
  z:integer;
  a:array[1..maxn]of byte;

function check(x:longint):boolean;
var
  i:longint;
begin
  check:=true;
  for i:=2 to trunc(sqrt(x)) do
    if x mod i=0 then
    begin
      if i>10 then begin writeln(-1); halt; end;
      check:=false;
      exit;
    end;
end;

procedure solve(x:longint);
var
  i:integer;
begin
  if check(x) then
    if x<10 then
    begin
      z:=z+1;
      a[z]:=x;
      exit;
    end
    else
    begin
      writeln(-1);
      halt;
    end;
  for i:=9 downto 2 do
    if x mod i=0 then
    begin
      flag:=false;
      z:=z+1;
      a[z]:=i;
      x:=x div i;
      solve(x);
      break;
    end;
end;

begin
  readln(n);
  flag:=true;
  fillchar(a,sizeof(a),0);
  z:=0;
  if n=0 then writeln(10) else
  if (n>=1) and (n<=9) then writeln(n) else
  begin
    solve(n);
    for i:=z downto 1 do write(a[i]);
  end;
  writeln;
end.
Re: Why I am Wrong,please help me.
Posted by Ivan Georgiev 16 Jun 2002 15:37
your program prints 1 sometimes..
for example the tests
252 - the answer is 479 you print 1479
72 - the answer is 89 you print 189

good luck.