|
|
back to boardCommon Board---Problem1139----This code also doesn't work. Please Look!!!! 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!!!! 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!!!! 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 |
|
|