Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <map>
- using namespace std;
- const int mx = 1000005;
- int sd[mx + 1] = {1, 1};
- template <bool nodcalc> struct detnum {
- map <int, int> fact;
- detnum <false> *nodfact;
- detnum(int x) {
- while (x > 1) {
- fact[sd[x]]++;
- x /= sd[x];
- }
- if (nodcalc) {
- for (auto &x : fact) {
- nodfact->multiply(x.second + 1);
- }
- }
- }
- detnum() {}
- detnum &multiply(const detnum &d) {
- for (auto &x : d.fact) {
- if (nodcalc) nodfact->divide(fact[x.first] + 1);
- fact[x.first] += x.second;
- if (nodcalc) nodfact->multiply(fact[x.first] + 1);
- }
- return *this;
- }
- detnum ÷(const detnum &d) {
- for (auto &x : d.fact) {
- if (nodcalc) nodfact->divide(fact[x.first] + 1);
- fact[x.first] -= x.second;
- if (nodcalc) nodfact->multiply(fact[x.first] + 1);
- }
- return *this;
- }
- template <bool nc> bool divisible(const detnum <nc> &d) {
- for (auto &x : d.fact) {
- if (fact[x.first] < x.second) return false;
- }
- return true;
- }
- bool refactorable() {
- return divisible(*nodfact);
- }
- };
- void solve() {
- int n, q, x;
- char k;
- cin >> n >> q;
- detnum <true> facm(n), facn;
- facn = facm;
- while (q--) {
- cin >> k;
- if (k == '2') facn = facm;
- else {
- cin >> x;
- cout << (facn.multiply(x).refactorable() ? "YES\n" : "NO\n");
- }
- }
- cout << '\n';
- }
- signed main() {
- #ifdef ONLINE_JUDGE
- ios::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- #endif
- for (int i = 2; i <= mx; i++) {
- if (!sd[i]) {
- sd[i] = i;
- for (int j = 2; i * j <= mx; j++) {
- if (!sd[i * j]) sd[i * j] = i;
- }
- }
- }
- int t;
- cin >> t;
- while (t--) solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement