eolymp
bolt
Try our new interface for solving problems
Məsələlər

Vive la Difference!

Vive la Difference!

Take any four positive integers: \textbf{a}, \textbf{b}, \textbf{c}, \textbf{d}. Form four more, like this: \textbf{|a-b| |b-c| |c-d| |d-a|} That is, take the absolute value of the differences of \textbf{a} with \textbf{b}, \textbf{b} with \textbf{c}, \textbf{c} with \textbf{d}, and \textbf{d} with \textbf{a}. (Note that a zero could crop up, but they’ll all still be non-negative.) Then, do it again with these four new numbers. And then again. And again. Eventually, all four integers will be the same. For example, start with \textbf{1}, \textbf{3}, \textbf{5}, \textbf{9}: 1 3 5 9 2 2 4 8 (\textbf{1}) 0 2 4 6 (\textbf{2}) 2 2 2 6 (\textbf{3}) 0 0 4 4 (\textbf{4}) 0 4 0 4 (\textbf{5}) 4 4 4 4 (\textbf{6}) In this case, the sequence converged in \textbf{6} steps. It turns out that in all cases, the sequence converges very quickly. In fact, it can be shown that if all four integers are less than \textbf{2^n}, then it will take no more than \textbf{3·n} steps to converge! Given \textbf{a}, \textbf{b}, \textbf{c} and \textbf{d}, figure out just how quickly the sequence converges. \InputFile There will be several test cases in the input. Each test case consists of four positive integers on a single line (\textbf{1} ≤ \textbf{a}, \textbf{b}, \textbf{c}, \textbf{d} ≤ \textbf{2,000,000,000}), with single spaces for separation. The input will end with a line with four \textbf{0}s. \OutputFile For each test case, output a single integer on its own line, indicating the number of steps until convergence. Output no extra spaces, and do not separate answers with blank lines.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 32 MiB
Giriş verilənləri #1
1 3 5 9
4 3 2 1
1 1 1 1
0 0 0 0
Çıxış verilənləri #1
6
4
0
Mənbə 2011 ACM ICPC Southeast USA Regional Programming Contest