malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long a[5];   char x[4];   long long res = 1e14;   inline long long calc(long long x, long long y, char xx) {     if (xx ==  * ) return x * y;     return x + y;   }   int main() {     register int i, j;     for (i = 1; i <= 4; i++) cin >> a[i];     for (i = 1; i <= 3; i++) cin >> x[i];     int f[5] = {0, 1, 2, 3, 4};     do {       long long A = calc(a[f[1]], a[f[2]], x[1]);       long long B = calc(A, a[f[3]], x[2]);       long long T1 = calc(B, a[f[4]], x[3]);       A = calc(a[f[1]], a[f[2]], x[1]);       B = calc(a[f[3]], a[f[4]], x[2]);       long long T2 = calc(A, B, x[3]);       res = min(res, min(T1, T2));     } while (next_permutation(f + 1, f + 5));     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int i;     string b, a;     cin >> b;     int size = b.size();     for (i = 0; i <= size - 1; i++) {       a += b[i];       i++;     }     a += b[size - 1];     cout << a <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     getline(cin, s);     int _t = stoi(s);     while (_t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 7;   int main() {     long long n;     cin >> n;     for (long long a = 0; a < n / 1234567 + 1; a++)       for (long long b = 0; b < n / 123456 + 1; b++) {         long long c = n - a * 1234567 - b * 123456;         if (c >= 0 && c % 1234 == 0) {           cout <<  YES  << endl;           return 0;         }       }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k, x, y;     cin >> n >> k;     for (int i = 0; i < n - 1; ++i) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     int kol = 0;     for (int i = 1; i <= n; ++i) {       if ((int)g[i].size() == 1) kol++;     }     cout << fixed << setprecision(7) << k / (double)(kol)*2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005, mod = 1e9 + 7;   inline int Add(int x, int y) { return (x += y) >= mod ? x - mod : x; }   int n, cnt[maxn], vec[maxn], tot;   int main() {     scanf( %d , &n);     cnt[0] = 1;     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x), tot = 0;       for (int j = 1; j * j <= x; ++j) {         if (x % j == 0) {           vec[++tot] = j;           if (j * j != x && x / j <= n)             cnt[x / j] = Add(cnt[x / j], cnt[x / j - 1]);         }       }       for (int j = tot; j; --j)         if (vec[j] <= n) cnt[vec[j]] = Add(cnt[vec[j]], cnt[vec[j] - 1]);     }     int ans = 0;     for (int i = 1; i <= n; ++i) ans = Add(ans, cnt[i]);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, x;       cin >> n >> x;       long long int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       int j = 1, teams = 0;       for (int i = n - 1; i >= 0; i--) {         if (a[i] * j >= x) {           teams++;           j = 0;         }         j++;       }       cout << teams << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   const long long LIMIT = 2e18 + 1;   int n;   long long k;   long long arr[N];   long long cnt[N];   bool isUnsafe(long long a, long long b) {     return a > LIMIT / b || b > LIMIT / a;   }   int solve(int i) {     int res = 0;     long long s, p;     if (arr[i] != 1) {       s = k * arr[i];       p = arr[i];       res += (s == p);     } else {       s = k * cnt[i];       p = 1;       res += (k == 1);     }     for (++i; i < n; ++i) {       if (arr[i] == 1) {         long long sOld = s;         s += k * cnt[i];         if (sOld < p && s >= p && (p - sOld) % k == 0) {           ++res;         }       } else {         if (isUnsafe(p, arr[i])) {           break;         }         p *= arr[i];         s += k * arr[i];         if (s == p) {           ++res;         }       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 0; i < n; ++i) {       cin >> arr[i];       if (i > 0 && arr[i] == 1 && arr[i - 1] == 1) {         --i;         --n;       }       ++cnt[i];     }     long long res = 0;     for (int i = 0; i < n; ++i) {       res += solve(i);       if (arr[i] == 1) {         --cnt[i];         if (cnt[i]) {           --i;         }       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long double pi = acos(-1.0);   const long double eps = 1e-9;   const int MAX_SIZE = 50;   const int dX[] = {-1, 1, 0, 0, -1, 1, -1, 1};   const int dY[] = {0, 0, -1, 1, 1, -1, -1, 1};   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& a) {     o << a.first <<     << a.second;     return o;   }   template <class S, class T>   ostream& operator<<(ostream& o, const map<S, T>& a) {     for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)       o << (*it) <<   n ;     return o;   }   template <class S>   ostream& operator<<(ostream& o, const vector<S>& a) {     for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)       o << *it <<    ;     return o;   }   template <class S>   ostream& operator<<(ostream& o, const vector<vector<S> >& a) {     for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) {       o << (*it) <<   n ;     }     return o;   }   template <class S>   ostream& operator<<(ostream& o, const set<S>& a) {     for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)       o << *it <<    ;     return o;   }   const long long MAX = 2005;   int a[MAX][MAX];   long long diagl[MAX * 2], diagr[MAX * 2];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     int i, j, n, x1, y1, x2, y2;     long long val, max1 = 0, max2 = 0;     scanf( %d , &n);     for (i = (0); (((1) > 0) - ((1) < 0)) * i < (((1) > 0) - ((1) < 0)) * (n);          i += (1)) {       for (j = (0); (((1) > 0) - ((1) < 0)) * j < (((1) > 0) - ((1) < 0)) * (n);            j += (1)) {         scanf( %d , &a[i][j]);         diagl[i + j] += a[i][j];         diagr[n - (i - j) - 1] += a[i][j];       }     }     for (i = (0); (((1) > 0) - ((1) < 0)) * i < (((1) > 0) - ((1) < 0)) * (n);          i += (1)) {       for (j = ((i % 2));            (((2) > 0) - ((2) < 0)) * j < (((2) > 0) - ((2) < 0)) * (n);            j += (2)) {         val = diagl[i + j] + diagr[n - (i - j) - 1] - a[i][j];         if (val >= max1) {           max1 = val;           x1 = i + 1;           y1 = j + 1;         }       }       for (j = ((1 - (i % 2)));            (((2) > 0) - ((2) < 0)) * j < (((2) > 0) - ((2) < 0)) * (n);            j += (2)) {         val = diagl[i + j] + diagr[n - (i - j) - 1] - a[i][j];         if (val >= max2) {           max2 = val;           x2 = i + 1;           y2 = j + 1;         }       }     }     printf( %I64 d n%d %d %d %d , max1 + max2, x1, y1, x2, y2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 260;   const int MOD = 1000000000 + 7;   int n, m, t;   int mid;   int v[N], mod[N];   bool g[10][N];   long long ans, f[10];   inline void Dfs(int k, int d) {     ans += f[d];     if (ans > MOD) ans -= MOD;     if (d > 5) return;     for (int i = k; i <= mid; i++)       if (v[i] && !g[d][i] && !g[d][m - i]) {         if (d < 5) {           for (int j = 0; j < m; j++) g[d + 1][j] = g[d][j];           for (int j = 0; j < m; j++)             if (g[d][j]) g[d + 1][mod[j + i]] = g[d + 1][mod[j + m - i]] = 1;         }         f[d + 1] = (f[d] * v[i]) % MOD;         Dfs(i + 1, d + 1);       }   }   int main() {     int x;     for (scanf( %d %d %d , &n, &m, &t); t--; v[((x) < (m - x) ? (x) : (m - x))]++)       scanf( %d , &x), x %= m;     mid = m / 2;     for (int i = 0; i <= 2 * m; i++) mod[i] = i % m;     f[0] = 1;     g[0][0] = 1;     Dfs(1, 0);     printf( %d n , (int)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, h, l, r;   int a[2000 + 5], dp[2000 + 5][2000 + 5];   int solve(int curr, int idx) {     if (idx == n) {       if (l <= curr && curr <= r)         return 1;       else         return 0;     }     if (dp[curr][idx] != -1) return dp[curr][idx];     int p1 = 0, p2 = 0;     if (l <= curr && curr <= r) {       p1 = 1;       p2 = 1;     }     p1 += solve((curr + a[idx]) % h, idx + 1);     p2 += solve((curr + a[idx] - 1) % h, idx + 1);     return dp[curr][idx] = max(p1, p2);   }   int main(int argc, const char* argv[]) {     scanf( %d %d %d %d , &n, &h, &l, &r);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i <= h; i++) {       for (int j = 0; j <= n; j++) {         dp[i][j] = -1;       }     }     int k = solve(a[0], 1);     for (int i = 0; i <= h; i++) {       for (int j = 0; j <= n; j++) {         dp[i][j] = -1;       }     }     k = max(k, solve(a[0] - 1, 1));     printf( %d n , k);     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e6 + 10;   const int maxm = 1e5 + 10;   const long long int mod = 1e9 + 7;   const long long int INF = 1e18 + 100;   const int inf = 0x3f3f3f3f;   const double pi = acos(-1.0);   const double eps = 1e-8;   using namespace std;   int n, m;   int cas, tol, T;   struct Sam {     int node[maxn << 1][27], step[maxn << 1], fa[maxn << 1];     int dp[maxn << 1], tax[maxn << 1], gid[maxn << 1];     int vis[maxn << 1];     int last, sz;     int newnode() {       memset(node[++sz], 0, sizeof node[++sz]);       dp[sz] = step[sz] = fa[sz] = 0;       return sz;     }     void init() {       sz = 0;       last = newnode();     }     void insert(int k) {       int p = last, np = last = newnode();       dp[np] = 1;       step[np] = step[p] + 1;       for (; p && !node[p][k]; p = fa[p]) node[p][k] = np;       if (p == 0) {         fa[np] = 1;       } else {         int q = node[p][k];         if (step[q] == step[p] + 1) {           fa[np] = q;         } else {           int nq = newnode();           memcpy(node[nq], node[q], sizeof(node[q]));           fa[nq] = fa[q];           step[nq] = step[p] + 1;           fa[np] = fa[q] = nq;           for (; p && node[p][k] == q; p = fa[p]) node[p][k] = nq;         }       }     }     void handle() {       for (int i = 0; i <= sz; i++) tax[i] = 0;       for (int i = 1; i <= sz; i++) tax[step[i]]++;       for (int i = 1; i <= sz; i++) tax[i] += tax[i - 1];       for (int i = 1; i <= sz; i++) gid[tax[step[i]]--] = i;       for (int i = sz; i >= 1; i--) {         int u = gid[i];         dp[fa[u]] += dp[u];       }     }     int solve(char *s, int len, int id) {       int p = 1, res = 0;       int ans = 0;       for (int i = 1; i <= len + len; i++) {         int k = s[i] -  a  + 1;         while (p && !node[p][k]) {           p = fa[p];           res = step[p];         }         if (p == 0) {           p = 1;           res = 0;         } else {           p = node[p][k];           res++;           if (res >= len) {             int tmp = p;             while (tmp && vis[tmp] != id &&                    !(step[fa[tmp]] + 1 <= len && len <= step[tmp])) {               vis[tmp] = id;               tmp = fa[tmp];             }             if (vis[tmp] != id) {               vis[tmp] = id;               ans += dp[tmp];             }           }         }       }       return ans;     }   } sam;   char s[maxn], t[maxn << 1];   int main() {     scanf( %s , s + 1);     int slen = strlen(s + 1);     sam.init();     for (int i = 1; i <= slen; i++) {       sam.insert(s[i] -  a  + 1);     }     sam.handle();     scanf( %d , &T);     for (int tt = 1; tt <= T; tt++) {       scanf( %s , t + 1);       int tlen = strlen(t + 1);       for (int i = 1; i <= tlen; i++) {         t[i + tlen] = t[i];       }       t[tlen + tlen + 1] =   0 ;       int ans = sam.solve(t, tlen, tt);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   string tostring(T x) {     ostringstream out;     out << x;     return out.str();   }   long long toint(string s) {     istringstream in(s);     long long x;     in >> x;     return x;   }   int main() {     int n, x, tmp;     cin >> n >> x;     int ans = 0, zero = 0;     for (int i = 0; i < n; i++) {       cin >> tmp;       ans += tmp;     }     if (ans == 0) {       cout << 0 << endl;     } else {       ans = ((ans < 0) ? -(ans) : (ans));       if (ans % x == 0) {         cout << ans / x << endl;       } else {         cout << ans / x + 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void past_code();   vector<int> v[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int x, y, j, k;     cin >> x;     for (int i = 1; i <= 2 * x; i++) {       cin >> y;       v[y].push_back(i);     }     long long sum = 0;     j = 1;     k = 1;     for (int i = 1; i <= x; i++) {       sum += abs(j - v[i][0]) + abs(k - v[i][1]);       j = v[i][0];       k = v[i][1];     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n = 0, s = 0, d = 0;   map<int, vector<int> > graph;   map<int, bool> vis;   bool stop = false;   void Dfs(int m) {     if (m == d || stop) {       cout << m;       stop = true;       return;     }     cout << m <<    ;     for (int i = 0; i < (int)graph[m].size(); i++) {       if (vis.find(graph[m][i]) == vis.end()) {         vis[graph[m][i]] = true;         Dfs(graph[m][i]);       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s >> d;       graph[s].push_back(d);       graph[d].push_back(s);     }     vector<int> k;     for (map<int, vector<int> >::iterator it = graph.begin(); it != graph.end();          it++) {       if ((*it).second.size() == 1) {         k.push_back((*it).first);       }     }     s = k[0], d = k[1];     vis[s] = true;     Dfs(s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(51);   const long long INF = 1e18;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       vector<vector<long long>> a(n, vector<long long>(m)),           pr(n, vector<long long>(m));       vector<vector<long long>> mn(m, vector<long long>(m, INF));       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           char c;           cin >> c;           a[i][j] = c -  0 ;           pr[i][j] = a[i][j] + (j > 0 ? pr[i][j - 1] : 0);         }       }       long long anss = 1e18;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           for (long long jj = j; jj < m; jj++) {             if (jj - j + 1 >= 4) {               if (i > 0)                 mn[j][jj] += (a[i - 1][j] ^ 1) + (a[i - 1][jj] ^ 1) +                              (pr[i - 1][jj - 1] - pr[i - 1][j]);               if (i - 4 >= 0) {                 long long add = 0;                 for (long long f = i - 3; f < i; f++) {                   add +=                       (a[f][j] ^ 1) + (a[f][jj] ^ 1) + (pr[f][jj - 1] - pr[f][j]);                 }                 mn[j][jj] =                     min(mn[j][jj],                         (jj - j - 1) - (pr[i - 4][jj - 1] - pr[i - 4][j]) + add);               }               anss = min(anss,                          mn[j][jj] + (jj - j - 1) - (pr[i][jj - 1] - pr[i][j]));             }           }         }       }       cout << anss << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e6 + 7;   inline long long stoll(char* s, const long long& p, bool f = 0) {     long long a = 0;     bool fl = 0;     for (; *s; ++s) a = a * 10 + *s - 48, fl |= (f && a >= p), a %= p;     return a + fl * p;   }   long long b, n, p, phi;   char B[M], N[M];   inline long long fp(long long x, long long k, const long long& p) {     long long r = 1;     for (; k; k >>= 1, x = x * x % p)       if (k & 1) r = r * x % p;     return r;   }   inline long long getphi(long long n) {     long long r = n, nn = n;     for (long long i = 2; i * i <= nn; ++i)       if (!(n % i))         for (r = r / i * (i - 1); !(n % i); n /= i)           ;     if (n > 1) r = r / n * (n - 1);     return r;   }   inline long long mod(long long x, long long p) {     return x < p ? x : x % p + p;   };   inline char* N_1() {     register int s = strlen(N) - 1;     for (; s >= 0 && !N[s]; --s)       ;     --N[s];     return N;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> B >> N >> p;     phi = getphi(p);     b = stoll(B, p), n = stoll(N_1(), phi, 1);     long long ans = ((b - 1) * fp(b, n, p) + p) % p;     if (!(ans)) ans = p;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     pair<int, int> friendlist[100001];     scanf( %d%d , &n, &d);     for (int i = 0; i < n; i++)       scanf( %d%d , &((friendlist + i)->first), &((friendlist + i)->second));     sort(friendlist, friendlist + n);     int it_left = 0;     int it_right = 0;     long long maxfriendship = 0;     long long friendship = 0;     while (true) {       while (it_right < n &&              friendlist[it_right].first - friendlist[it_left].first < d) {         friendship += friendlist[it_right].second;         maxfriendship = max(maxfriendship, friendship);         it_right++;       }       if (it_right >= n) break;       while (friendlist[it_right].first - friendlist[it_left].first >= d) {         friendship -= friendlist[it_left].second;         it_left++;       }     }     cout << maxfriendship;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 * 1000 + 7, MAX_LOG = 20;   int n, m;   vector<int> adj[MAXN];   bool isPassed[MAXN];   int par[MAXN][MAX_LOG], cycleCnt[MAXN], h[MAXN];   void pre(int root) {     isPassed[root] = true;     for (auto nei : adj[root]) {       if (!isPassed[nei]) {         par[nei][0] = root;         h[nei] = h[root] + 1;         pre(nei);         cycleCnt[root] = cycleCnt[root] + cycleCnt[nei];       } else if (par[root][0] != nei and h[nei] < h[root]) {         cycleCnt[nei]--;         cycleCnt[root]++;       }     }     return;   }   int nanCyCnt[MAXN][MAX_LOG];   void dfs(int root, int lstRt) {     par[root][0] = lstRt;     if (lstRt != -1 and cycleCnt[root] == 0) nanCyCnt[root][0] = 1;     for (int i = 1; i < MAX_LOG and h[root] >= (1 << i) and                     par[par[root][i - 1]][i - 1] != -1;          ++i) {       par[root][i] = par[par[root][i - 1]][i - 1];       nanCyCnt[root][i] =           nanCyCnt[root][i - 1] + nanCyCnt[par[root][i - 1]][i - 1];     }     isPassed[root] = true;     for (auto nei : adj[root]) {       if (!isPassed[nei]) {         h[nei] = h[root] + 1;         dfs(nei, root);       }     }     return;   }   int lca(int v, int u) {     int nancy = 0;     if (h[v] > h[u]) swap(v, u);     for (int i = 0; h[v] ^ h[u]; ++i) {       if ((h[u] - h[v]) & (1 << i)) {         nancy += nanCyCnt[u][i];         u = par[u][i];       }     }     if (v == u) return nancy;     for (int i = MAX_LOG - 1; i >= 0; --i) {       if (par[v][i] != par[u][i]) {         nancy += (nanCyCnt[v][i] + nanCyCnt[u][i]);         v = par[v][i], u = par[u][i];       }     }     return nancy + nanCyCnt[v][0] + nanCyCnt[u][0];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(par, -1, sizeof par);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int v, u;       cin >> v >> u, v--, u--;       adj[v].push_back(u);       adj[u].push_back(v);     }     memset(isPassed, 0, sizeof isPassed);     pre(0);     memset(isPassed, 0, sizeof isPassed);     memset(h, 0, sizeof h);     dfs(0, -1);     int mercsNum;     cin >> mercsNum;     while (mercsNum--) {       int sh, wa;       cin >> wa >> sh, wa--, sh--;       cout << lca(wa, sh) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int a[200003], b[200003], f[200003];   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     int i, l, h;     for (i = 0; i < n; i++) {       scanf( %d%d , &l, &h);       a[l]++;       a[h + 1]--;     }     int sum = 0, co = 0;     for (i = 0; i <= 200000; i++) {       if (a[i] != 0) sum += a[i];       a[i] = sum;       if (a[i] >= m) {         co++;         f[i] = 1;       }       b[i] = co;     }     for (i = 0; i < q; i++) {       scanf( %d%d , &l, &h);       if (f[l] == 1)         printf( %d n , b[h] - b[l] + 1);       else         printf( %d n , b[h] - b[l]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline bool isPrime(uint64_t n) {     if (n == 1) return false;     if (n == 2) return true;     if (n % 2 == 0) return false;     for (uint64_t div = 3; div * div <= n; div += 2)       if (n % div == 0) return false;     return true;   }   inline std::vector<uint64_t> generatePrimesUntil(uint64_t upperBound) {     if (upperBound < 2) return {};     std::vector<uint64_t> result = {2};     for (uint64_t candidate = 3; candidate <= upperBound; candidate += 2) {       bool divisibleByPrevious = false;       for (size_t divisorIndex = 1;            divisorIndex < result.size() &&            result[divisorIndex] * result[divisorIndex] <= candidate;            ++divisorIndex) {         if (candidate % result[divisorIndex] == 0) {           divisibleByPrevious = true;           break;         }       }       if (!divisibleByPrevious) result.push_back(candidate);     }     return result;   }   inline std::vector<std::pair<uint64_t, uint64_t>> decomposeToPrimePowers(       uint64_t n) {     std::vector<std::pair<uint64_t, uint64_t>> result;     auto tryPrime = [&](uint64_t p) {       if (n % p == 0) {         result.push_back({p, 0});         while (n % p == 0) {           n /= p;           result.back().second++;         }       }     };     tryPrime(2);     for (uint64_t primeCandidate = 3; primeCandidate * primeCandidate <= n;          primeCandidate += 2)       tryPrime(primeCandidate);     if (n > 1) result.push_back({n, 1});     return result;   }   template <typename T>   void printVector(const std::vector<T>& out, std::string delimiter =    ) {     if (out.empty()) return;     for (size_t i = 0; i < out.size() - 1; ++i) std::cout << out[i] << delimiter;     std::cout << out.back();   }   class Solver576A {    public:     void run();   };   void Solver576A::run() {     int n;     cin >> n;     auto primes = generatePrimesUntil(n);     vector<int> ans;     for (auto p : primes)       for (int pp = p; pp <= n; pp *= p) ans.push_back(pp);     cout << ans.size() <<   n ;     printVector(ans);   }   using CurrentSolver = Solver576A;   int main() {     ios::sync_with_stdio(false);     CurrentSolver().run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007, BIG = 0x3f3f3f3f;   long long p, k;   inline long long Mod(long long x, long long m) {     x %= m;     if (x < 0) x += m;     return x;   }   vector<long long> Process() {     vector<long long> ans;     while (p) {       const long long m = Mod(p, k);       ans.push_back(m);       p -= m;       p /= -k;     }     return ans;   }   void Output() {     const vector<long long> ans = Process();     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     while (cin >> p) {       cin >> k;       Output();     }     return 0;   }