POJ 2115 拓展欧几里德算法

题解

$Cx+2^ky=B-A$

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

typedef long long ll;
ll A, B, C, k;

ll extgcd(ll a, ll b, ll &x, ll &y)
{
ll d = a;
if (b != 0)
{
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}
else
{
x = 1, y = 0;
}
return d;
}

int main()
{
while (~scanf("%lld%lld%lld%lld", &A, &B, &C, &k) && (A | B | C | k))
{
if (A == B)
{
printf("0\n");
continue;
}
if (C == 0)
{
printf("FOREVER\n");
continue;
}
ll a = C, b = (ll)1 << k, c = B - A;
ll x, y;
ll gcd = extgcd(a, b, x, y);
if (c % gcd != 0)
{
printf("FOREVER\n");
}
else
{
ll mod = b / gcd;
x *= c / gcd;
x = (x % mod + mod) % mod;
printf("%lld\n", x);
}
}
return 0;
}


09-26

05-20 121

01-13

08-27 7

02-23 3万+

04-19 7

02-27 4万+

04-14 59万+

07-22 134

03-13 15万+

03-01 13万+

03-04 14万+

03-08 5万+

03-08 7万+

04-25 6万+

03-10 13万+

03-12 11万+

03-13 11万+

03-14 1万+

03-18 9905

03-19 3万+

03-19 8万+

03-19 3万+

03-22 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-27 1万+

03-29 21万+

03-29 10万+

03-30 16万+

05-31 6286

05-31 1万+

04-02 5600

04-02 4万+

04-06 7万+

04-09 8万+

04-09 2万+

05-17 8556

04-11 3万+

04-15 6万+

04-18 4万+

04-20 4万+

04-24 3万+

04-29 7067

04-30 1万+

04-30 9572

05-01 6425

05-03 1万+

05-16 5万+

05-06 1万+

05-08 4万+

05-10 3310

05-14 6520

05-14 1992

05-16 3599

05-16 1万+

05-20 999

05-18 8421

05-27 1449

05-18 3614

05-19 1万+

05-21 7576

05-21 7600

05-27 5206

05-25 5393

05-23 6549

05-28 1683

05-23 3067

05-24 8493

05-25 6159

05-25 3543

05-25 4290

05-25 977

05-25 4194

05-25 1239

太牛了！关于高并发系统设计看这篇就够了！

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试