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

Discussion of Problem 1302. Delta-wave

Why WA#7??? {Почему WA#7???}
Posted by SIAL_snipious_Pimenov(Пименов) 13 Oct 2005 14:02
label a1;
var n, m, r, nn, mn, nm, mm: longint;
begin
     read(n, m);
     if m > n then begin
        r := m;
        m := n;
        n := r;
     end;
     nn := round(int(sqrt(n - 1)));
     mn := round(int(sqrt(m - 1)));
     if nn = mn then begin
        nm := n - nn * nn;
        mm := m - mn * mn;
        r := abs(mm - nm);
        goto a1;
     end;
     r := nn - mn;
     r := r * 2;
     r := r - 1;
     nm := n - nn * nn;
     mm := m - mn * mn;
     if m mod 2 - mn mod 2 = 0 then
        r := r + 1;
     if abs(n mod 2 - nn mod 2) = 1 then
        r := r + 1;
     if (nm - mm > nn - mn + 1) then
        r := r + ((abs(nm - mm) - 1) div 2) * 2;
     if (mm - nm + 1 > nn - mn) then
        r := r + ((abs(nm - mm) + 1) div 2) * 2;
a1:  writeln(r);
end.

Edited by author 14.10.2005 20:52