malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long N = 998244353;   struct mat {     long long a[2][2];   };   mat mul(mat a, mat b) {     mat c;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 2; j++) {         c.a[i][j] = 0;         for (int k = 0; k < 2; k++) c.a[i][j] += a.a[i][k] * b.a[k][j];         c.a[i][j] %= N;       }     }     return c;   }   mat make_mat(long long x, long long y) {     mat ret;     ret.a[0][0] = x;     ret.a[1][0] = y;     ret.a[0][1] = 1;     ret.a[1][1] = 0;     return ret;   }   mat val[2000005];   void pushup(int x) { val[x] = mul(val[(x << 1)], val[((x << 1) | 1)]); }   void modify(int x, int l, int r, int pos, mat v) {     if (l == r) {       val[x] = v;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid) modify((x << 1), l, mid, pos, v);     if (pos > mid) modify(((x << 1) | 1), mid + 1, r, pos, v);     pushup(x);   }   int n, m, x, y, d[500005];   string s;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     cin >> s;     reverse(s.begin(), s.end());     s =     + s;     for (int i = 1; i <= n; i++) {       d[i] = s[i] -  0 ;       modify(1, 1, n, i,              make_mat(d[i] + 1, (i == 1 ? 0 : (d[i] == 1) * (9 - d[i - 1]))));     }     while (m--) {       cin >> x >> y;       x = n - x + 1;       d[x] = y;       modify(1, 1, n, x,              make_mat(d[x] + 1, (x == 1 ? 0 : (d[x] == 1) * (9 - d[x - 1]))));       if (x < n)         modify(1, 1, n, x + 1,                make_mat(d[x + 1] + 1, (d[x + 1] == 1) * (9 - d[x])));       cout << val[1].a[0][0] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 4e18;   const int MAX_LOG = 21;   const int MAX_N = (1 << 17);   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k, a, b, c, d;     cin >> n >> k >> a >> b >> c >> d;     if (n < 5 || k < n + 1) {       cout << -1 << endl;     } else {       int arr[n];       arr[0] = a, arr[n - 1] = b, arr[1] = c, arr[n - 2] = d;       vector<bool> taken(n + 1);       taken[a] = taken[b] = taken[c] = taken[d] = true;       int id = 1;       for (int i = 2; i < n - 2; i++) {         while (taken[id]) {           id++;         }         arr[i] = id;         taken[id] = true;       }       for (int i = 0; i < n; i++) {         cout << arr[i] <<    ;       }       cout << endl;       vector<int> v;       v.push_back(c);       v.push_back(a);       v.push_back(arr[2]);       for (int i = 3; i <= n - 3; i++) {         v.push_back(arr[i]);       }       v.push_back(b);       v.push_back(d);       for (int x : v) {         cout << x <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   bool comp(int x, int y) { return x > y; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int tt = 1;     long long m, n, k;     while (tt--) {       cin >> n >> k;       vector<int> vec(n);       for (long long i = 0; i < n; i++) {         cin >> vec[i];       };       sort(vec.begin(), vec.end());       set<int> s;       for (long long i = 0; i < n; i++) {         s.insert(vec[i]);       }       if (s.size() != n) {         cout << 0 << endl;       } else {         for (long long i = 0; i < n; i++) {           int no = vec[i] & k;           if (no == vec[i])             ;           if (no == vec[i] and               binary_search(vec.begin() + i + 1, vec.end(), no)) {             cout << 1 << endl;             return 0;           } else if (no != vec[i] and binary_search(vec.begin(), vec.end(), no)) {             cout << 1 << endl;             return 0;           }         }         s.clear();         for (long long i = 0; i < n; i++) {           s.insert(vec[i] & k);         }         if (s.size() != n)           cout << 2 << endl;         else           cout << -1 << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100005], res = 1e9, A, B, x[100005], kq[100005], kq1[100005], dem = 0,                     e[100005];   void no(int val) {     if (a[n] >= 0 || a[n - 1] >= 0 || res <= val) return;     res = val;     for (int i = 2; i <= n - 1; i++) kq[i] = x[i];     return;   }   void xuli(int i, int val) {     if (val >= res) return;     if (i == 2 || i == n - 1 || 1 == 1) {       for (int j = 0; j <= 16; j++) {         bool ok = true;         x[i] = j;         a[i - 1] -= B * j;         a[i] -= A * j;         a[i + 1] -= B * j;         if (a[i - 1] >= 0) ok = false;         if (ok == true) {           if (i == n - 1)             no(val + j);           else             xuli(i + 1, val + j);         }         a[i - 1] += B * j;         a[i] += A * j;         a[i + 1] += B * j;       }     } else {       int tg = max(e[i] / A + 1, max(e[i - 1] / B + 1, e[i + 1] / B + 1));       for (int j = 0; j <= tg; j++) {         bool ok = true;         x[i] = j;         a[i - 1] -= B * j;         a[i] -= A * j;         a[i + 1] -= B * j;         if (a[i - 1] >= 0) ok = false;         if (ok == true) {           if (i == n - 1)             no(val + j);           else             xuli(i + 1, val + j);         }         a[i - 1] += B * j;         a[i] += A * j;         a[i + 1] += B * j;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> A >> B;     for (int i = 1; i <= n; i++) cin >> a[i], e[i] = a[i];     xuli(2, 0);     cout << res <<   n ;     for (int i = 2; i <= n - 1; i++)       for (int j = 1; j <= kq[i]; j++) kq1[++dem] = i;     for (int i = 1; i <= dem; i++) cout << kq1[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int l, r;     cin >> l >> r;     vector<long long int> v, ans;     long long int x = 1;     while (x <= r) {       v.push_back(x);       x *= 2;     }     x = 1;     while (x <= r) {       for (auto i : v) {         long long int y = x * i;         if (y > r) break;         ans.push_back(y);       }       x *= 3;     }     sort(ans.begin(), ans.end());     long long int n = 0;     for (auto i : ans) {       if (i >= l && i <= r) n++;     }     cout << n;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005];   int main(void) {     int n;     stack<int> s;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = n; i >= 1; i--) {       if (s.empty()) {         s.push(a[i]);         b[i] = 0;         continue;       }       if (a[i] < s.top()) {         s.push(a[i]);         b[a[i]] = 0;       } else if (a[i] > s.top()) {         int temp = max(1, b[s.top()]);         s.pop();         while (!s.empty() && a[i] > s.top()) {           temp = max(temp + 1, b[s.top()]);           s.pop();         }         b[a[i]] = temp;         s.push(a[i]);       }     }     int k = 0;     for (int i = 1; i <= n; i++) k = max(k, b[i]);     printf( %d n , k);   }
#include <bits/stdc++.h>   int dp[200100];   int X[200100];   int Y[200100];   int T[200100];   int MX[200100];   int main(void) {     int n, r;     scanf( %d %d , &r, &n);     for (int i = 1; i <= n; i++) dp[i] = MX[i] = -200100;     MX[0] = X[0] = Y[0] = dp[0] = T[0] = 0;     for (int i = 1; i <= n; i++) {       scanf( %d %d %d , &T[i], &X[i], &Y[i]);       X[i]--;       Y[i]--;       for (int j = i - 1; j >= 0; j--) {         if (T[i] - T[j] > r * 2) {           dp[i] = std::max(dp[i], MX[j] + 1);           break;         };         int xdiff = std::abs(X[i] - X[j]);         int ydiff = std::abs(Y[i] - Y[j]);         if (xdiff + ydiff <= T[i] - T[j]) {           dp[i] = std::max(dp[i], dp[j] + 1);         };       };       MX[i] = std::max(MX[i - 1], dp[i]);     };     printf( %d n , MX[n]);     return 0;   };
#include <bits/stdc++.h>   using namespace std;   struct node {     int u, v;   };   node p[200010];   int du[200010], n, m;   int _first[200010], _next[200010], _to[200010], cnt;   int add(int a, int b) {     _next[++cnt] = _first[a];     _first[a] = cnt;     _to[cnt] = b;     du[b]++;   }   bool check(int x) {     cnt = 0;     bool ok = 1;     int now;     for (int i = 1; i <= n; i++) du[i] = 0, _first[i] = 0;     for (int i = 1; i <= x; i++) add(p[i].u, p[i].v);     for (int i = 1; i <= n; i++) {       if (!ok && !du[i]) return false;       if (!du[i]) now = i, ok = 0;     }     if (ok) return false;     while (_first[now]) {       ok = 1;       for (int i = _first[now]; i; i = _next[i]) {         du[_to[i]]--;         if (!ok && !du[_to[i]]) return false;         if (!du[_to[i]]) now = _to[i], ok = 0;       }     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &p[i].u, &p[i].v);       if (p[i].u == 0 || p[i].v == 0) return 0;     }     int l = 1, r = m, ans = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     scanf( %lld , &n);     scanf( %lld , &m);     long long int i, j;     string s;     cin >> s;     long long int arr[400], brr[400];     for (i = 1; i <= 300; i++) {       arr[i] = i;       brr[i] = i;     }     while (m--) {       char a, b;       cin >> a >> b;       long long int ind1 = brr[a];       long long int ind2 = brr[b];       arr[ind1] = b;       arr[ind2] = a;       brr[b] = ind1;       brr[a] = ind2;     }     for (i = 0; i < (long long int)s.size(); i++) {       s[i] = (char)arr[s[i]];     }     cout << s <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   vector<long long> p;   int ho, mi, se;   void fix_time() {     if (se > 59) mi += se / 60, se = se % 60;     if (se < 0) se += 60, mi--;     if (mi > 59) ho += mi / 60, mi = mi % 60;     if (mi < 0) mi += 60, ho--;     if (ho < 0) ho += 24;     if (ho > 24) ho -= 24;   }   long long my_pow(int x, int y) {     long long num = 1;     for (long long i = x; y > 0; i = (i * i), y >>= 1)       if (y & 1) num = (num * i);     return num;   }   bool prime[1000001], prime2[1000001];   void sieve() {     for (int i = 2; i <= 1000000; i += 2) prime[i] = false, prime[i - 1] = true;     prime[2] = true;     for (int i = 3; i * i <= 1000000; i += 2)       if (prime[i])         for (int j = i * i; j <= 1000000; j += 2 * i) prime[j] = false;   }   vector<int> vv;   int cnt = 0;   void pfact(long long x) {     if (x % 2 == 0) {       p.push_back(2);       while (x % 2 == 0) x /= 2, cnt++;       vv.push_back(cnt);     }     for (long long i = 3; i * i <= x; i += 2)       if (x % i == 0) {         cnt = 0;         p.push_back(i);         while (x % i == 0) x /= i, cnt++;         vv.push_back(cnt);       }     if (x > 1) p.push_back(x), cnt++, vv.push_back(1);   }   int gcd(int a, int b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   int m, x, n, y, z, k, mx, one, gd, x2, y2, two, mn = 1e9, mid, l, r, pos,                                                   a[500003], b[500003], c[500000];   string s2;   vector<int> v, v2[100003];   long long sum, ans, num;   char ch;   map<string, int> mp1;   set<int> myset;   string s, s1;   int tmp;   bool yes, lft, rt;   multiset<string> lfts[100001], rts[100001];   int t, sum2, y3, z3;   bool used;   int main() {     ios_base::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n;       bool res[n];       memset(res, 0, n);       vector<pair<pair<int, int>, int> > myvec;       for (int i = 0; i < n; i++) {         cin >> x >> y;         myvec.push_back({{y, x}, i});       }       sort(myvec.begin(), myvec.end());       int ind = myvec[0].second;       int beg = myvec[0].first.second;       int en = myvec[0].first.first;       res[ind] = true;       vector<int> shits;       for (int i = 1; i < n; i++) {         m = i;         int f = myvec[i].first.first;         int se = myvec[i].first.second;         ind = myvec[i].second;         if (en >= se) {           if (beg > se) beg = se;           en = f;           shits.push_back(ind);           for (int j = 0; j < shits.size(); j++) res[shits[j]] = true;           shits.clear();         } else           shits.push_back(ind);       }       yes = false;       for (int i = 0; i < n; i++)         if (!res[i]) yes = true;       if (yes)         for (int i = 0; i < n; i++)           if (res[i])             cout <<  1  ;           else             cout <<  2  ;       else         cout << -1;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<16 * 2002> dp[1 << 16];   int n, k;   int a[16];   int weight[16];   int calc(int &x) {     int c = 0;     while (x % k == 0) x /= k, c++;     return c;   }   int _calc(int x) {     int c = 0;     while (x % k == 0) x /= k, c++;     return c;   }   void dfs(int s, int x) {     if (__builtin_popcount(s) == 1) return;     int y = x, z = x;     while (y < 16 * 2002) {       if (dp[s][y]) z = y;       y = y * k;     }     if (z != x) {       for (int i = 0; i < n; i++)         if ((1 << i) & s) weight[i] += _calc(z / x);       dfs(s, z);     } else {       for (int i = 0; i < n; i++)         if ((1 << i) & s and x >= a[i] and dp[s ^ (1 << i)][x - a[i]]) {           dfs(s ^ (1 << i), x - a[i]);           break;         }     }   }   signed main() {     dp[0][0] = 1;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i < (1 << n); i++) {       for (int j = 0; j < n; j++)         if (i & (1 << j)) dp[i] |= (dp[i - (1 << j)] << a[j]);       for (int j = 16 * 2000 / k; j >= 0; j--)         if (dp[i][j * k]) dp[i][j] = 1;     }     if (!dp[(1 << n) - 1][1]) return puts( NO ) * 0;     puts( YES );     dfs((1 << n) - 1, 1);     int cnt = n - 1;     while (cnt--) {       int f1 = -1, f2 = -1;       for (int i = 0; i < n; i++) {         if (f1 == -1 or weight[i] > weight[f1])           f2 = f1, f1 = i;         else if (f2 == -1 or weight[i] > weight[f2])           f2 = i;       }       printf( %d %d n , a[f1], a[f2]);       a[f1] += a[f2];       weight[f2] = -1e9;       weight[f1] -= calc(a[f1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, i, a[5];     cin >> n;     for (i = 0; i < 5; i++) {       a[i] = n % 10;       n /= 10;     }     n = a[3] + 10 * a[1] + 100 * a[0] + 1000 * a[2] + 10000 * a[4];     m = n;     m = n * n;     m %= 100000;     m = m * n;     m %= 100000;     m = m * n;     m %= 100000;     m = m * n;     m %= 100000;     if (m < 10000) {       cout <<  0 ;     }     if (m < 1000) {       cout <<  0 ;     }     if (m < 100) {       cout <<  0 ;     }     if (m < 10) {       cout <<  0 ;     }     cout << m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n + 5];       for (int i = 0; i < n; i++) cin >> a[i];       int ans = 1;       for (int i = 1; i <= 26; i++) {         int x = 1;         while (true) {           int count = 0;           int j, k;           for (j = 0; j < n; j++) {             if (a[j] == i) count++;             if (count == x) break;           }           int count1 = 0;           for (k = n - 1; k >= 0; k--) {             if (a[k] == i) count1++;             if (count1 == x) break;           }           if (j == n || k == -1) break;           if (j >= k) break;           vector<int> freq;           for (int l = 0; l <= 27; l++) freq.push_back(0);           for (int l = j + 1; l < k; l++) freq[a[l]]++;           int y = 0;           for (int l = 0; l <= 26; l++) y = max(y, freq[l]);           ans = max(ans, 2 * x + y);           x++;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1000000 + 10;   long long d[maxn];   long long ans = 0;   int main() {     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long v, u;       cin >> v >> u;       d[u]++;       d[v]++;     }     for (long long i = 1; i <= n; i++) ans += d[i] * (n - 1 - d[i]);     cout << (n * (n - 1) * (n - 2)) / 6 - (ans / 2) << endl;     return 0;   }
#include <bits/stdc++.h>   int n;   char S[300000];   struct edge {     int to, nxt;   } E[500000];   int H[500000], tot;   inline void add_edge(int a, int b) { E[++tot] = (edge){b, H[a]}, H[a] = tot; }   struct SegmentTree {     struct node {       node *L, *R;       node() { L = R = NULL; }     };     node *root;     void insert(node *&now, int l, int r, int k) {       if (!now) now = new node;       if (l == r) return;       int mdl = (l + r) >> 1;       if (k <= mdl)         insert(now->L, l, mdl, k);       else         insert(now->R, mdl + 1, r, k);     }     bool query(node *now, int l, int r, int L, int R) {       if (l > R || r < L || !now) return false;       if (L <= l && r <= R) return true;       int mdl = (l + r) >> 1;       return query(now->L, l, mdl, L, R) | query(now->R, mdl + 1, r, L, R);     }     SegmentTree() { root = NULL; }   };   SegmentTree::node *merge(SegmentTree::node *&A, SegmentTree::node *&B) {     if (!(A && B)) return A ? A : B;     SegmentTree::node *nw = new SegmentTree::node;     nw->L = merge(A->L, B->L), nw->R = merge(A->R, B->R);     return nw;   }   struct SAM {     struct node {       int son[26], len, link, R;       SegmentTree S;       node() {         memset(son, 0xff, sizeof(int) * 26);         len = link = R = 0;       }     } T[500000];     int tot, lst;     void insert(char C) {       C -=  a ;       int q = ++tot, p = lst;       T[q].len = T[p].len + 1,       T[q].S.insert(T[q].S.root, 1, n, T[q].R = T[q].len);       lst = q;       while (~p && !~T[p].son[C]) T[p].son[C] = q, p = T[p].link;       if (!~p) return;       int np = T[p].son[C];       if (T[p].len + 1 == T[np].len)         T[q].link = np;       else {         int nq = ++tot;         memcpy(T[nq].son, T[np].son, sizeof(int) * 26);         T[nq].link = T[np].link;         T[nq].len = T[p].len + 1;         T[np].link = T[q].link = nq;         while (~p && T[p].son[C] == np) T[p].son[C] = nq, p = T[p].link;       }     }     SAM() { tot = lst = 0, T[0].link = -1; }   } G;   void pre(int now) {     for (int i = H[now]; i; i = E[i].nxt) {       pre(E[i].to);       G.T[now].R = std::max(G.T[now].R, G.T[E[i].to].R);       G.T[now].S.root = merge(G.T[now].S.root, G.T[E[i].to].S.root);     }   }   int Ans;   void solve(int now, int ans, int top) {     Ans = std::max(Ans, ans);     for (int i = H[now]; i; i = E[i].nxt) {       if (G.T[top].S.query(G.T[top].S.root, 1, n,                            G.T[E[i].to].R - G.T[E[i].to].len + G.T[top].len,                            G.T[E[i].to].R - 1))         solve(E[i].to, ans + 1, E[i].to);       else         solve(E[i].to, ans, top);     }   }   int main() {     scanf( %d%s , &n, S + 1);     if (n == 1) return puts( 1 ), 0;     for (int i = 1; i <= n; i++) G.insert(S[i]);     for (int i = 1; i <= G.tot; i++) add_edge(G.T[i].link, i);     pre(0), solve(0, 0, 0);     printf( %d n , Ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 45;   int a[maxn], b[maxn];   const long long INFF = 0x3f3f3f3f3f3f3f3fll;   int N;   struct Martix {     long long arr[maxn][maxn];     void init() { memset(arr, 0x3f, sizeof(arr)); }     void to() {       this->init();       for (int i = 0; i < N; i++) {         arr[i][i] = 0;       }     }     void out() {       for (int i = 0; i < N; i++) {         for (int j = 0; j < N; j++) {           long long v = arr[i][j] == INFF ? -1 : arr[i][j];           cout << v <<    ;         }         cout << endl;       }       puts( -- );     }   };   Martix operator*(const Martix& a, const Martix& b) {     Martix ret;     ret.init();     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         for (int k = 0; k < N; k++) {           ret.arr[i][j] = min(ret.arr[i][j], a.arr[i][k] + b.arr[k][j]);         }       }     }     return ret;   }   long long dp[maxn][maxn][maxn];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) scanf( %d , &b[i]);     memset(dp, 0x3f, sizeof(dp));     N = n + 1;     for (int i = 0; i < N; i++) {       dp[i][i][0] = 0;     }     for (int k = 1; k <= n; k++) {       for (int i = 0; i < N; i++) {         for (int j = 0; j < N; j++) {           if (j - 1 >= 0)             dp[i][j][k] = min(dp[i][j][k], dp[i][j - 1][k - 1] + a[k - 1]);           if (j + 1 < N)             dp[i][j][k] = min(dp[i][j][k], dp[i][j + 1][k - 1] + b[k - 1]);         }       }     }     Martix x;     x.init();     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         x.arr[i][j] = dp[i][j][n];       }     }     Martix ret;     ret.to();     while (m) {       if (m & 1) ret = ret * x;       x = x * x;       m >>= 1;     }     printf( %I64d n , ret.arr[0][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7LL;   const int MAXN = 212345;   int vis[MAXN];   vector<int> g[MAXN];   long long dfs(int u) {     vis[u] = 1;     long long r = 1;     for (int v : g[u])       if (!vis[v]) r += dfs(v);     return r;   }   long long fexp(long long b, long long e) {     if (b == 1 || e == 0) return 1;     if (b == 0) return 0;     long long resp = fexp(b, e / 2);     resp = ((resp % MOD) * (resp % MOD)) % MOD;     if (e & 1) resp = ((resp % MOD) * (b % MOD)) % MOD;     return resp % MOD;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     for (int i = 0, u, v, w; i < n - 1; ++i) {       cin >> u >> v >> w;       if (!w) {         g[u].push_back(v);         g[v].push_back(u);       }     }     long long r = fexp(n, k);     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         r = (r % MOD - fexp(dfs(i), k) % MOD) % MOD;         if (r < 0) r += MOD;         r %= MOD;       }     }     cout << r <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long powmod(long long base, long long exponent, long long mod) {     long long ans = 1;     while (exponent) {       if (exponent & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       exponent /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   const int upperlimit = 71;   const int mod = 998244353;   long long fact[upperlimit];   long long invfact[upperlimit];   vector<long long> pdv;   void func(long long n) {     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) pdv.push_back(i);       while (n % i == 0) n /= i;     }     if (n > 1) pdv.push_back(n);   }   int pw(long long n, long long i) {     int ans = 0;     while (n % i == 0) {       ans++;       n /= i;     }     return ans;   }   int main() {     fact[0] = 1;     invfact[0] = 1;     for (int i = 1; i < upperlimit; i++) {       fact[i] = fact[i - 1];       fact[i] *= i;       fact[i] %= mod;       invfact[i] = powmod(fact[i], mod - 2, mod);     }     long long d, u, v;     int q;     long long temp = 1;     int lol = 0;     scanf( %lld , &d);     func(d);     scanf( %d , &q);     while (q--) {       scanf( %lld , &u);       scanf( %lld , &v);       long long gc = gcd(u, v);       temp = 1;       lol = 0;       for (int i = 0; i < pdv.size(); i++) {         int gg = abs(pw(gc, pdv[i]) - pw(u, pdv[i]));         temp *= invfact[gg];         temp %= mod;         lol += gg;       }       temp *= fact[lol];       temp %= mod;       lol = 0;       for (int i = 0; i < pdv.size(); i++) {         int gg = abs(pw(gc, pdv[i]) - pw(v, pdv[i]));         temp *= invfact[gg];         temp %= mod;         lol += gg;       }       temp *= fact[lol];       temp %= mod;       printf( %lld n , temp);     }     return 0;   }