#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std
;
int main() {
int a
, b
;
int aa
, aaa
, bb
, bbb
;
while(~scanf
("%d%d",&a
,&b
)) {
if(a
== b
) { puts
("0");
continue;
}
if(a
> b
) swap
(a
, b
); aa
= (int)sqrt
(1.0*a
);
if(aa
* aa
== a
) aa
--; aaa
= a
- aa
* aa
; bb
= (int)sqrt
(1.0*b
);
if(bb
* bb
== b
) bb
--; bbb
= b
- bb
* bb
;
//printf("aa : %d , aaa : %d\n",aa,aaa);
//printf("aaa : %d , bbb : %d\n",bb,bbb);
int left1
, right1
, left2
, right2
;
int delta
= 0;
if(aa
== bb
) { printf
("%d\n",bbb
- aaa
);
continue;
}
if(aaa
% 2 == 0) { delta
++; left1
= aaa
/ 2; right1
= left1
+ 1;
}
else left1
= right1
= (aaa
+ 1) / 2;
if(bbb
% 2 == 1) { delta
++; left2
= bbb
/ 2; right2
= left2
+ 1;
}
else left2
= right2
= bbb
/ 2;
//printf("left1 is %d , right1 is %d\n",left1 , right1);
//printf("left2 is %d , right2 is %d\n",left2 , right2);
delta
+= (bb
- aa
- 1) * 2; right1
+= bb
- aa
- 1;
if(bbb
>= left1
&& bbb
<= right1
) ;
else if(left2
>= left1
&& left2
<= right1
) ;
else if(right2
>= left1
&& right2
<= right1
) ;
else { delta
+= 2 * min
(abs
(left1
- right2
) , abs
(left2
- right1
));
} delta
+= 1; printf
("%d\n",delta
);
}
return 0;
}
posted on 2012-10-18 17:59
YouAreInMyHeart 阅读(111)
评论(0) 编辑 收藏 引用