#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
void Ex_Gcd(LL a, LL b, LL &d, LL &x, LL &y)
{
if(b == 0)
{
x = 1;
y = 0;
d = a;
return ;
}
else
{
Ex_Gcd(b, a%b, d, x, y);
LL temp = x;
x = y;
y = temp - (a/b)*y;
}
}
int main()
{
LL a, b, c, k;
LL d, x0, y0;
while(scanf("%I64d%I64d%I64d%I64d", &a, &b, &c, &k))
{
if((a+b+c+k) == 0)
break;
LL temp = c;
c = b-a;
a = temp;
b = (LL)1<<k;//这一块要注意 LL 不能省略
Ex_Gcd(a, b, d, x0, y0);
if(c % d != 0)
{
printf("FOREVER\n");
continue;
}
else
{
LL t = b/d;
x0 = x0 * (c/d);
x0 = (x0%t + t)%t;
printf("%I64d\n", x0);
}
}
return 0;
}
poj 2115 C Looooops
最新推荐文章于 2021-11-18 13:52:17 发布