进制转换
string conversion(string num, int m, int n) {int l = num.size(), k = 0;string ans = "";for (int i = 0; i < l;) {k = 0;for (int j = i; j < l; j++) {int t = (k * m + num[j] - '0') % n;num[j] = (k * m + num[j] - '0') / n + '0';k = t;}ans += (k + '0');while (num[i] == '0') i++;}return ans;
}
线性筛
int prime[N], n, k;
bool isprime[N];
void get_prime() {memset(isprime, 1, sizeof(isprime));for (int i = 2; i <= n; ++i) {if (isprime[i]) prime[k++] = i;for (int j = 0; j < k && i * prime[j] <= n; ++j) {isprime[i * prime[j]] = false;if (i % prime[j]) break;}}
}
并查集
int tree[N];
int find(int x) {if (tree[x] == x) return x;return tree[x] = find(tree[x]);
}
void unit(int x, int y) {x = find(x), y = find(y);if (x != y) tree[y] = x;
}
void init(int n) {for (int i = 1; i <= n; ++i) tree[i] = i;
}
bool same(int x, int y) { return find(x) == find(y); }