{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eA Compiler Mystery: We are given a C-language style for loop of type\u003c/p\u003e\n\n\n\u003cp\u003efor (variable \u003d A; variable !\u003d B; variable +\u003d C)\u003cbr\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;statement;\u003c/p\u003e\n\n\u003cp\u003eI.e., a loop which starts by setting variable to value A and while variable is not equal to B, repeats statement followed by increasing the variable by C. We want to know how many times does the statement get executed for particular values of A, B and C, assuming that all arithmetics is calculated in a k-bit unsigned integer type (with values 0 \u0026lt;\u003d x \u0026lt; 2k) modulo 2k.\u003c/p\u003e\n\n\n\n\u003cb\u003e\u003cp\u003eInput\u003c/p\u003e\u003c/b\u003e\n\n\u003cp\u003eThe input consists of several instances. Each instance is described by a single line with four integers A, B, C, k separated by a single space. The integer k (1 \u0026lt;\u003d k \u0026lt;\u003d 32) is the number of bits of the control variable of the loop and A, B, C (0 \u0026lt;\u003d A, B, C \u0026lt; 2k) are the parameters of the loop.\u003c/p\u003e\n\n\u003cp\u003eThe input is finished by a line containing four zeros.\u003c/p\u003e\n\n\n\u003cb\u003e\u003cp\u003eOutput\u003c/p\u003e\u003c/b\u003e\n\n\u003cp\u003eThe output consists of several lines corresponding to the instances on the input. The i-th line contains either the number of executions of the statement in the i-th instance (a single integer number) or the word FOREVER if the loop does not terminate.\u003c/p\u003e\n\n\n\u003cb\u003e\u003cp\u003eSample Input\u003c/p\u003e\u003c/b\u003e\n\n\u003cp\u003e\n3 3 2 16\u003cbr\u003e\n3 7 2 16\u003cbr\u003e\n7 3 2 16\u003cbr\u003e\n3 4 2 16\u003cbr\u003e\n0 0 0 0\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cb\u003e\u003cp\u003eSample Output\u003c/p\u003e\u003c/b\u003e\n\n\u003cp\u003e\n0\u003cbr\u003e\n2\u003cbr\u003e\n32766\u003cbr\u003e\nFOREVER\u003cbr\u003e\n\u003c/p\u003e"}}]}