1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstdlib> 5 #include <algorithm> 6 using namespace std; 7 int main() 8 { 9 int n, m; 10 while (cin >> n >> m) 11 { 12 13 int Za = (int)ceil(sqrt(n * 1.0)); 14 int Zb = (int)ceil(sqrt(m * 1.0)); 15 int Xa = (Za * Za - n) / 2 + 1; 16 int Xb = (Zb * Zb - m) / 2 + 1; 17 int Ya = (n - (Za - 1) * (Za - 1) - 1) / 2 + 1; 18 int Yb = (m - (Zb - 1) * (Zb - 1) - 1) / 2 + 1; 19 20 int ans = abs(Za - Zb) + abs(Xa - Xb) + abs(Ya - Yb); 21 printf("%d\n", ans ); 22 } 23 }