program c; procedure check(a, b, c: longint; k: byte); var pretykac: longint; i: longint; sumx: longint; ok: boolean; amin: longint; timeout: longint; begin if c=0 then if a=b then begin writeln('0'); exit; end else begin writeln('FOREVER'); exit; end; pretykac := 1 shl k; amin := pretykac; ok := false; timeout := 100000; for i:=0 to pretykac do begin sumx := b + pretykac*i - a; if (sumx>=0) and ((sumx mod c)=0) then begin writeln(sumx div c); { writeln('sumx: ', sumx); writeln('pretykac: ', pretykac); writeln('i: ', i); writeln('c: ', c); } ok := true; end; if ok then break; dec(timeout); if timeout<=0 then break; end; if not(ok) then writeln('FOREVER'); end; var a, b, c, k: longint; begin while true do begin readln(a, b, c, k); if (a=0) and (b=0) and (c=0) and (k=0) then break; check(a, b, c, k); end; end.