|  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
 | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define debug(x) cout << #x << " is " << x << endl
#define inc(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;
const int INF = 0x3f3f3f3f;
void exgcd(ll a, ll b, ll &x, ll &y) {
	if (!b) x = 1, y = 0;
	else exgcd(b, a % b, y, x), y -= a / b * x;
}
inline ll mul(ll x, ll y, ll p) { // 会爆 long long
	ll z = (long double)x / p * y;
	ll res = (unsigned long long)x * y - (unsigned long long)z * p;
	return (res + p) % p;
}
ll qpow(ll a, ll x, ll p) {
	a %= p;
	ll res = 1;
	for (; x; x >>= 1, a = mul(a, a, p))
		if (x & 1) res = mul(res, a, p);
	return res;
}
int main() 
{
	ll n = 1001733993063167141, d = 212353, c = 20190324, p, q;
	/*for (ll i = 3; i * i < n; i += 2) {
		if (n % i == 0) {
			p = i;
			q = n / i;
			break;
		}
	}
	printf("p = %lld, q = %lld;\n", p, q);*/
	p = 891234941, q = 1123984201;
	ll m = (p - 1) * (q - 1), x, y, e;
	exgcd(d, m, x, y);
	e = (x % m + m) % m;
	printf("%lld\n", qpow(c, e, n));
    return 0;
}
 |