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

Common Board

---Problem1139----This code also doesn't work. Please Look!!!!
Posted by Vitaliy Surovyi 10 Aug 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!!!!
Posted by GodZilla 11 Aug 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!!!!
Posted by GodZilla 11 Aug 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