/*------------------------------------------------------------------------------ * problem020.c: Steps (6.6.8) **----------------------------------------------------------------------------*/ /* Copyright (c) 2009 Peter Bui. All Rights Reserved. * * Peter Bui * **------------------------------------------------------------------------------ * Includes **----------------------------------------------------------------------------*/ #include #include #include /*------------------------------------------------------------------------------ * Functions **----------------------------------------------------------------------------*/ static int compute_steps(int x, int y) { int d, s, c; d = y - x; s = 0; c = 0; while (1) { if ((y - x) <= 0) break; if (abs(y - x - c) <= 1) { s += 1; break; } c += 1; x += c; y -= c; s += 2; } return (s); } /*------------------------------------------------------------------------------ * Main Execution **----------------------------------------------------------------------------*/ int main(int argc, char* argv[]) { int x, y; while (scanf("%d %d", &x, &y) != EOF) printf("%d\n", compute_steps(x, y)); return (EXIT_SUCCESS); } /*------------------------------------------------------------------------------ * vim: sts=4 sw=4 ts=8 ft=c **----------------------------------------------------------------------------*/