#include <stdio.h> long long mod(long long a,long long b) { return (a % b + b) % b; } struct triple { long long d,x,y; }; long long Euclid(long long a,long long b) { if(b == 0) return a; else return Euclid(b,mod(a,b)); } triple Extended_Euclid(long long a,long long b) { triple result; if(b == 0) { result.d = a; result.x = 1; result.y = 0; } else { triple ee = Extended_Euclid(b,mod(a,b)); result.d = ee.d; result.x = ee.y; result.y = ee.x - (a/b)*ee.y; } return result; } long long MLES(long long a,long long b,long long n) { triple ee = Extended_Euclid(a,n); if(mod(b,ee.d) == 0) return mod((ee.x * (b / ee.d)),n/ee.d); else return -1; } int main() { long long A, B, C, k; while(scanf("%I64d%I64d%I64d%I64d", &A, &B, &C, &k) && !(A==0&&B==0&&C==0&&k==0)) { if(A == B) { printf("0/n"); continue; } long long ret = MLES(C, B-A, ((long long)1)<<k); //((long long)1)<<k //这儿要注意,1<<32位后,会超过int的最大值,需要转换为long long if(ret == -1) printf("FOREVER/n"); else printf("%I64d/n", ret); } return 0; }