ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1083. Факториалы!!!

whi it is wrong? help me please
Послано I am david. Tabo. 12 апр 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...
Послано Vladimir Milenov Vasilev 13 апр 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!
Послано I am david. Tabo. 10 май 2002 00:39