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 1083. Factorials!!!

whi it is wrong? help me please
Posted by I am david. Tabo. 12 Apr 2002 22:58
var i,j,n:integer;
    sg:longint;
    x,k,l:byte;
    s:string;

procedure readdata;
  begin
    read (n,s);
  end;

procedure solve;
   begin
    k:=length(s)-1;
    sg:=n;
    x:=1;
    for j:=1 to n do
      begin
        if n mod k <> 0 then
          begin
            if (j=n)and(x=2) then
              sg:=sg*(n mod k)
            else
              if (n>=j*k)and((n-j*k)<>1)and((n-j*k)<>0) then
                begin
                  x:=2;
                  sg:=sg*(n-j*k);
                end
              else
                if sg=0 then
                  begin
                    sg:=0;
                    exit;
                  end;
          end
        else
          begin
            if (j=n)and(x=2) then
              sg:=sg*k
            else
              if (n>=j*k)and((n-j*k)<>1)and((n-j*k)<>0) then
                begin
                  sg:=sg*(n-j*k);
                  x:=2;
                end
              else
                if sg=0 then
                  begin
                    sg:=0;
                    exit;
                  end;
          end;
      end;
  end;

procedure print;
  begin
    writeln (sg);
  end;
begin
  readdata;
  solve;
  print;
end.

I think this is gonna help...
Posted by Vladimir Milenov Vasilev 13 Apr 2002 04:49
> var i,j,n:integer;
>     sg:longint;
>     x,k,l:byte;
>     s:string;
>
> procedure readdata;
>   begin
>     read (n,s);
>   end;
>
> procedure solve;
>    begin
>     k:=length(s)-1;
>     sg:=n;
>     x:=1;
>     for j:=1 to n do
>       begin
>         if n mod k <> 0 then
>           begin
>             if (j=n)and(x=2) then
>               sg:=sg*(n mod k) {Here !!!}
>             else
>               if (n>=j*k)and((n-j*k)<>1)and((n-j*k)<>0) then
>                 begin
>                   x:=2;
>                   sg:=sg*(n-j*k);  {And here you take the same
number eventuallu!!!!!, look at my example....}
{
>                 end
>               else
>                 if sg=0 then
>                   begin
>                     sg:=0;
>                     exit;
>                   end;
>           end
>         else
>           begin
>             if (j=n)and(x=2) then
>               sg:=sg*k
>             else
>               if (n>=j*k)and((n-j*k)<>1)and((n-j*k)<>0) then
>                 begin
>                   sg:=sg*(n-j*k);
>                   x:=2;
>                 end
>               else
>                 if sg=0 then
>                   begin
>                     sg:=0;
>                     exit;
>                   end;
>           end;
>       end;
>   end;
>
> procedure print;
>   begin
>     writeln (sg);
>   end;
> begin
>   readdata;
>   solve;
>   print;
> end.
>
> Hi!
I think, you take one and same number two times
For example, if input is:
5 !!!
You output 20, but the wright answer is 10.
> "if (j=n)and(x=2) then
>               sg:=sg*(n mod k)"
I think, you dont need this - take it out and will have Accepted(dont
forget that you have used this and when "n%k=0"!!!!!
HAve a look at this Idea, too:
t=n;
while(t>0) do
Begin
 dec(t,k);
 if (t>1) n=n*t;
End;
writeln(n);
Bye!!!
Thenck your I got AC!
Posted by I am david. Tabo. 10 May 2002 00:39