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

Общий форум

---Problem1139----This code also doesn't work. Please Look!!!!
Послано Vitaliy Surovyi 10 авг 2003 21:33
I took this classic algorythm N+M-GCD(M,N) but this doesn't work.
Maybe output or something...

Var
   N,M,Ost,NSD,Bil,Men : Longint;
Begin
Read(N);Read(M);
Bil:=N;Men:=M;
While (Men<>0)And(Bil<>0) Do
If Men>Bil Then Men:=Men Mod Bil Else Bil:=Bil Mod Men;
NSD:=Men+Bil;
Writeln(N+M-NSD);
End.
Re: ---Problem1139----This code also doesn't work. Please Look!!!!
Послано GodZilla 11 авг 2003 18:18
You got WA because there is some
strange with checkrer. I try to solve
this problem at first time and got WA.
Later i wrote other procedure for calculating
NSD and got AC
Re: ---Problem1139----This code also doesn't work. Please Look!!!!
Послано GodZilla 11 авг 2003 18:49
Here is AC one:

var a,b:longint;

function nod(a,b:longint):longint;
begin

 while a*b<>0 do
  if a>b then a:=a mod b else b:=b mod a;

 if a=0 then nod:=b else nod:=a;
end;

begin
 readln(a,b);
 write(a+b-nod(a-1,b-1)-2);
end.

If you need a help for solving other problem mail me VRomanchik@tut.by