poj 2115 C Looooops

来源:互联网 发布:微信数据恢复 编辑:程序博客网 时间:2024/05/12 12:59
#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;}

0 0
原创粉丝点击