1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include <cstdio> #include <cctype>
using namespace std;
template<typename T> inline void read(T &x) { x = 0; T k = 1; char in = getchar(); while (!isdigit(in)) { if (in == '-') k = -1; in = getchar(); } while (isdigit(in)) x = x * 10 + in - '0', in = getchar(); x *= k; }
typedef long long ll;
inline ll mul(ll a, ll b, ll p) { ll ans = 0; while (b) { if (b & 1) ans = (ans + a) % p; a = (a + a) % p; b >>= 1; } return ans; }
inline ll q_pow(ll a, ll b, ll p) { ll ans = 1; while (b) { if (b & 1) ans = mul(ans, a, p) % p; a = mul(a, a, p) % p, b >>= 1; } return ans; }
void exgcd(ll a, ll b, ll &x, ll &y, ll &g) { if (!b) x = 1, y = 0, g = a; else { exgcd(b, a%b, y, x, g); y -= a / b * x; } }
int main() { ll n, m, l, x, y, g, t; read(n), read(m), read(l); t = q_pow(2, m, n+1); exgcd(t, n+1, x, y, g); x = (x % (n+1) + n+1) % (n+1); printf("%lld\n", mul(x, l, n+1)); return 0; }
|