← Back to topics
Topic

intgrid

N
Nikola94
ne shvatam sta nije u redu sa kodom:
program intgrid;
var
x,y,d,u : longint;
function nzd(a,b : longint) :longint;
var
r: longint;
begin
repeat
r := a mod b;
a := b;
b := r;
until r = 0;
nzd := a;
end;

begin
readln(x,y);
d := nzd(x,y) - 1; //broj tacaka na hipotenuzi
u := trunc(((x*y) / 2)- ((d+x+y+2) / 2) +1); {vazi da je povrsina trougla jednaka: (x*y)/2 = u+ ((d+(x+1)+(y+1)/2) - 1, gde je u broj tacaka u unutrasnjosti trougla }
writeln(x+y+d+u+2)
end.


radi 30/50 test primera... moze neko da mi kaze sta nije u redu i zasto je na 12. test primeru exit code is not zero? hvala unapred
a
aleksa92
Evo ti formule pa probaj sa njom:
resenje=((x+1)*(y+1)+NZD(x,y)+1)/2
g
gates
If you want understand why this formula works check Pick's theorem.
N
Nikola94
@aleksa92:

upotrebio sam tvoju formulu ali sad radi 31/50 test primera, i dalje mi pokazuje "exit code is not zero" na 12. test primeru...
p
picsel
Use int64 instead of longint
N
Nikola94
@picsel:

now it's 48/50 but i don't get WR or TLE, i get exit code is not zero on tests 12 and 48... what's wrong ???
A
Al3kSaNdaR
Put this after readln.


If ( x = 0 ) Or ( y = 0 ) Then
Begin
WriteLn ( x + y + 1 );
Halt;
End;
N
Nikola94
thx al3ksandar now it works :)
g
gigac
I try it aleksa92 formula and I get Wrong result only on the last test case... What's the matter :?
h
halil
Try
  WriteLn( (((x+1)*(y+1) + GCD(x,y)+1) DIV 2) );


not ' / 2'
g
gigac
Thanks a looot :)))))))))