number⋅x+product⋅y=1 有整数x,y解的条件是gcd(number, product) == 1.
product用线段树维护一下,然后现学了个欧拉函数。
可以这样假如x = p1^a1 * p2^a2 * p3^a3 * ... * pn^an,那么phi(x) = (p1 - 1) * p1^(a1 - 1) + (p2 - 1) * p2^(a2 - 1) + (p3 - 1) * p3^(a3 - 1) + ... + (pn - 1) * pn^(an - 1).
速度奇慢,明早优化。。。
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define rep(i, a, b) for (int i = a; i <= b; i++) 4 #define drep(i, a, b) for (int i = a; i >= b; i--) 5 #define REP(i, a, b) for (int i = a; i < b; i++) 6 #define mp make_pair 7 #define pb push_back 8 #define clr(x) memset(x, 0, sizeof(x)) 9 #define xx first 10 #define yy second 11 int pri[] = { 0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281 }; 12 13 const int maxn = 100005, mod = 19961993; 14 int cnt[maxn << 2][61]; 15 void Push_up(int o) { rep(i, 1, 60) cnt[o][i] = cnt[o << 1][i] + cnt[o << 1 | 1][i]; } 16 void fac(int o, int v) { 17 rep(i, 1, 60) cnt[o][i] = 0; 18 while (v != 1) { 19 for (int i = 1; i <= 60 && v != 1; i++) 20 while (v != 1 && v % pri[i] == 0) cnt[o][i]++, v /= pri[i]; 21 } 22 } 23 void update(int o, int l, int r, int x, int v) { 24 if (l == r) { 25 fac(o, v); 26 return; 27 } 28 int mid = l + r >> 1; 29 if (x <= mid) update(o << 1, l, mid, x, v); 30 else update(o << 1 | 1, mid + 1, r, x, v); 31 Push_up(o); 32 } 33 int ret[61]; 34 void query(int o, int l, int r, int ql, int qr) { 35 if (ql <= l && r <= qr) { 36 rep(i, 1, 60) ret[i] += cnt[o][i]; 37 return; 38 } 39 int mid = l + r >> 1; 40 if (ql <= mid) query(o << 1, l, mid, ql, qr); 41 if (qr > mid) query(o << 1 | 1, mid + 1, r, ql, qr); 42 } 43 int POW(int base, int num) { 44 long long ha = 1; 45 long long b = base; 46 while (num) { 47 if (num & 1) ha *= b, ha %= mod; 48 b *= b; 49 b %= mod; 50 num >>= 1; 51 } 52 return ha; 53 } 54 int main() { 55 int n; scanf("%d", &n); 56 rep(i, 1, 100000) update(1, 1, 100000, i, 3); 57 while (n--) { 58 int op, x, y; scanf("%d%d%d", &op, &x, &y); 59 if (op == 1) update(1, 1, 100000, x, y); 60 else { 61 memset(ret, 0, sizeof(ret)); 62 query(1, 1, 100000, x, y); 63 long long ans = 1; 64 rep(i, 1, 60) { 65 if (!ret[i]) continue; 66 ans *= POW(pri[i], ret[i] - 1); 67 ans %= mod; 68 ans *= pri[i] - 1; 69 ans %= mod; 70 } 71 printf("%lld\n", ans); 72 } 73 } 74 }