text
stringlengths
49
983k
#include <bits/stdc++.h> const int INF = 1e9; const long long lINF = 1e18; const double EPS = 1e-12; using namespace std; const int N = 111; int n; int a[N], b[N]; map<int, long long> pa[N], push_back[N]; const int MOD = 1e9 + 7; void makenotcollinear(int i, int p1, int p2) { long long x1 = pa[0][p1], y1 = pa[0][p2]; long long dx1 = push_back[0][p1], dy1 = push_back[0][p2]; long long x2 = pa[i][p1], y2 = pa[i][p2]; long long dx2 = push_back[i][p1], dy2 = push_back[i][p2]; long long normx = -dy2, normy = dx2; long long want = (x2 - x1) * normx + (y2 - y1) * normy; long long step = dx1 * normx + dy1 * normy; assert(step != 0); long long mult = want / step; for (auto j : push_back[i]) { pa[0][j.first] += push_back[0][j.first] * mult; } } int power(int a, long long p) { int res = 1; for (; p; p >>= 1) { if (p & 1) { res = (res * 1ll * a) % MOD; } a = (a * 1ll * a) % MOD; } return res; } long long prod(long long a, long long b, long long curmod) { long long res = 0; bool flag = false; if (b < 0) { b = -b; flag = true; } for (; b; b >>= 1) { if (b & 1) { res = (res + a) % curmod; } a = a * 2 % curmod; } if (flag) { res = -res; } return res; } long long gcdExt(long long a, long long b, long long& M, long long& N) { if (b == 0) { M = 1; N = 0; return a; } else { long long k = a / b; long long res = gcdExt(b, a - k * b, M, N); swap(M, N); N -= k * M; return res; } } void solve() { bool ok = true; for (int i = 1; i < n && ok; i++) { vector<int> primes; for (auto j : pa[0]) { primes.push_back(j.first); } for (auto j : pa[i]) { primes.push_back(j.first); } for (auto j : push_back[i]) { primes.push_back(j.first); } long long mult = -1; for (auto j : primes) { long long want = pa[0][j]; long long have = pa[i][j]; if (push_back[i][j] == 0) { if (have != want) { ok = false; break; } } else { if (mult != -1) { if (mult * push_back[i][j] + have != want) { ok = false; break; } } else { mult = (want - have) / push_back[i][j]; if (mult < 0 || mult * push_back[i][j] + have != want) { ok = false; break; } } } } } if (ok) { int ans = 1; for (auto i : pa[0]) { ans = ans * 1ll * power(i.first, i.second) % MOD; } printf("%d\n", ans); } else { printf("-1\n"); } } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", a + i, b + i); if (b[i] != 1) { swap(a[i], a[0]); swap(b[i], b[0]); } } for (int i = 0; i < n; i++) { for (int j = 2; j * j <= a[i]; j++) { while (a[i] % j == 0) { a[i] /= j; pa[i][j]++; } } if (a[i] > 1) { pa[i][a[i]]++; } for (int j = 2; j * j <= b[i]; j++) { while (b[i] % j == 0) { b[i] /= j; push_back[i][j]++; } } if (b[i] > 1) { push_back[i][b[i]]++; } } int p1 = 2, p1cnt = 0; for (auto i : push_back[0]) { if (i.second != 0) { p1 = i.first; p1cnt = i.second; } } bool collinear = true; for (int i = 1; i < n; i++) { int cur = push_back[i][p1]; for (auto j : push_back[i]) { if (push_back[0][j.first] * cur != j.second * p1cnt) { makenotcollinear(i, p1, j.first); collinear = false; } } for (auto j : push_back[0]) { if (j.second * cur != push_back[i][j.first] * p1cnt) { makenotcollinear(i, p1, j.first); collinear = false; } } } if (!collinear) { solve(); } else { long long a = pa[0][p1]; long long b = push_back[0][p1]; if (b == 0) { solve(); } else { a %= b; bool ok = true; for (int i = 1; i < n; i++) { long long c = push_back[i][p1]; if (c == 0) { if (a != pa[i][p1] % b) { ok = false; break; } else { a = pa[i][p1]; continue; } } long long M, N; long long g = gcdExt(b, c, M, N); long long d = pa[i][p1]; if (a % g != d % g) { ok = false; break; } long long lcm = b / g * c; long long na = prod(M, b, lcm); na = prod(na, (d % c - a % c) / g, lcm); na += a; na %= lcm; if (na < 0) { na += lcm; } a = na; b = lcm; } if (!ok) { printf("-1\n"); } else { for (int i = 0; i < n; i++) { while (pa[i][p1] > a) { a += push_back[i][p1]; } } long long add = (a - pa[0][p1]) / push_back[0][p1]; for (auto& i : pa[0]) { i.second += push_back[0][i.first] * add; } solve(); } } } return 0; }
#include <bits/stdc++.h> using namespace std; void read(map<int, pair<long long, long long> > &mp) { int x, y; scanf("%d%d", &x, &y); for (int i = 2; i * i <= x; i++) if (x % i == 0) { int cnt = 0; for (; x % i == 0; x /= i, cnt++) ; mp[i].first += cnt; } if (x > 1) mp[x].first++; for (int i = 2; i * i <= y; i++) if (y % i == 0) { int cnt = 0; for (; y % i == 0; y /= i, cnt++) ; mp[i].second += cnt; } if (y > 1) mp[y].second++; } long long gcd(long long x, long long y) { if (x < 0) x = -x; if (y < 0) y = -y; for (; y;) { long long r = x % y; x = y; y = r; } return x; } long long mul(long long a, long long b, long long c) { long long s = 0; for (; b; b >>= 1) { if (b & 1) (s += a) >= c ? s -= c : 233; (a += a) >= c ? a -= c : 233; } return s; } long long power(long long a, long long b, long long c) { long long s = 1; for (; b; b /= 2, a = mul(a, a, c)) if (b & 1) s = mul(s, a, c); return s; } long long phi(long long x) { long long ans = x; for (long long i = 2; i * i <= x; i++) if (x % i == 0) { for (; x % i == 0; x /= i) ; ans -= ans / i; } if (x != 1) ans -= ans / x; return ans; } long long solve(long long a, long long b, long long c) { if (a == 0) return 0; if (b == 0) return c / a; long long ta = mul(power(a, phi(-b) - 1, -b), (c % (-b) + (-b)) % (-b), -b); long long tb = (c - ta * a) / b; if (tb < 0) { long long d = (-tb + a - 1) / a; ta += -b * d; tb += a * d; } return ta; } void GG() { puts("-1"); exit(0); } map<int, pair<long long, long long> > merge( map<int, pair<long long, long long> > a, map<int, pair<long long, long long> > b) { long long l = 0, la = 0, lb = 0, lc = 0; long long p = 0, px = 0, py = 0; map<int, pair<long long, long long> >::iterator it; for (it = b.begin(); it != b.end(); it++) a[it->first]; for (it = a.begin(); it != a.end(); it++) { pair<long long, long long> &pa = it->second, &pb = b[it->first]; long long A = pa.second, B = -pb.second, C = pb.first - pa.first, G = gcd(A, B); if (A == 0 && B == 0) { if (C) GG(); continue; } if (C % G) GG(); A /= G; B /= G; C /= G; if (A < 0 || (A == 0 && B < 0)) A = -A, B = -B, C = -C; if (p) { if (px * A + py * B != C) GG(); } else if (l) { if (la == A && lb == B) { if (lc != C) GG(); } else { long long X0 = A * lb - B * la, X1 = C * lb - B * lc; long long Y0 = B * la - A * lb, Y1 = C * la - A * lc; if (X1 % X0 || Y1 % Y0) GG(); l = 0; p = 1; px = X1 / X0; py = Y1 / Y0; if (px < 0 || py < 0) GG(); } } else { l = 1; la = A; lb = B; lc = C; } } if (l) { map<int, pair<long long, long long> > ans; for (it = a.begin(); it != a.end(); it++) ans[it->first] = pair<long long, long long>( it->second.first + it->second.second * solve(la, lb, lc), it->second.second * (-lb)); return ans; } else if (p) { map<int, pair<long long, long long> > ans; for (it = a.begin(); it != a.end(); it++) ans[it->first] = pair<long long, long long>( px * it->second.second + it->second.first, 0); return ans; } else return a; } map<int, pair<long long, long long> > a[105]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { read(a[i]); if (i != 1) a[i] = merge(a[i], a[i - 1]); } long long ans = 1; map<int, pair<long long, long long> >::iterator it; for (it = a[n].begin(); it != a[n].end(); it++) ans = 1ll * ans * power(it->first, it->second.first, 1000000007) % 1000000007; printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; long long read() { long long xx = 0, flagg = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') { flagg = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { xx = xx * 10 + ch - '0'; ch = getchar(); } return xx * flagg; } void pus(long long xx, long long flagg) { if (xx < 0) { putchar('-'); xx = -xx; } if (xx >= 10) pus(xx / 10, 0); putchar(xx % 10 + '0'); if (flagg == 1) putchar(' '); if (flagg == 2) putchar('\n'); return; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long g = exgcd(b, a % b, x, y), t = x; x = y; y = t - a / b * y; return g; } long long ksm(long long u, long long v) { long long o = 1; u %= 1000000007; while (v) { if (v & 1) o = o * u % 1000000007; u = u * u % 1000000007; v >>= 1; } return o; } long long n, p[2005], pn, a[105][2005], b[105][2005]; struct equation { long long A, B, C; equation() : A(0), B(0), C(0) {} equation(long long newA, long long newB, long long newC) : A(newA), B(newB), C(newC) {} }; long long empty(equation &t) { if (t.A == 0 && t.B == 0) return t.C; long long g = gcd(abs(t.A), abs(t.B)); if (t.C % g) return 1; t.A /= g; t.B /= g; t.C /= g; return 0; } long long merge(equation p, equation q, long long &x, long long &y) { long long D = p.A * q.B - p.B * q.A; x = p.C * q.B - q.C * p.B, y = p.A * q.C - p.C * q.A; if (D) { if (x % D || y % D) { x = -1; y = -1; return -1; } x /= D; y /= D; return 1; } if (x || y) { x = -1; y = -1; return -1; } return 0; } long long check(long long x) { if (x < 0) return -1; long long ans = 1, i, u, z; for (i = 2; i <= n; i++) { vector<long long> s; s.clear(); for (u = 1; u <= pn; u++) { z = a[1][u] * x + b[1][u] - b[i][u]; if (a[i][u]) { if (z % a[i][u]) return -1; s.push_back(z / a[i][u]); } else if (z) return -1; } sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); if (s.size() > 1 || (s.size() == 1 && s.front() < 0)) return -1; } for (i = 1; i <= pn; i++) ans = ans * ksm(p[i], a[1][i] * x + b[1][i]) % 1000000007; return ans; } long long i, j, x, y, u[105], v[105], c[105], d[105], m, minx, A, B, C, g, t, flag; int main() { n = read(); for (i = 1; i <= n; i++) { u[i] = read(); v[i] = read(); for (x = u[i], y = 2; y <= x / y; y++) if (x % y == 0) for (p[++pn] = y; x % y == 0; x /= y) ; if (x != 1) p[++pn] = x; for (x = v[i], y = 2; y <= x / y; y++) if (x % y == 0) for (p[++pn] = y; x % y == 0; x /= y) ; if (x != 1) p[++pn] = x; } if (n == 1) { pus(u[1], 2); return 0; } sort(p + 1, p + pn + 1); pn = unique(p + 1, p + pn + 1) - p - 1; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for (i = 1; i <= n; i++) { for (j = 1; j <= pn; j++) while (u[i] % p[j] == 0) { b[i][j]++; u[i] /= p[j]; } for (j = 1; j <= pn; j++) while (v[i] % p[j] == 0) { a[i][j]++; v[i] /= p[j]; } } x = 0; y = 0; long long u, v; for (i = 2; flag == 0 && i <= n; i++) for (u = 1; flag == 0 && u <= pn; u++) { equation p(a[1][u], -a[i][u], b[i][u] - b[1][u]); if (empty(p)) { pus(-1, 2); return 0; } if (p.B == 0 && p.A) { x = p.C / p.A; flag = 1; break; } for (v = u + 1; v <= pn; v++) { equation q(a[1][v], -a[i][v], b[i][v] - b[1][v]); t = merge(p, q, x, y); if (t == 1) { flag = 1; break; } if (t == -1) { pus(-1, 2); return 0; } } } if (flag) { pus(check(x), 2); return 0; } for (i = 2; i <= n; i++) for (u = 1; u <= pn; u++) if (a[1][u]) { A = a[1][u]; B = a[i][u]; C = b[i][u] - b[1][u]; g = exgcd(A, B, x, y); m++; minx = max(minx, (long long)ceil(1.0 * C / A)); c[m] = (C / g) * x % B; d[m] = B / g; break; } for (i = 2; i <= m; i++) { A = d[1]; B = d[i]; C = c[i] - c[1]; g = exgcd(A, B, x, y); if (C % g) { pus(-1, 2); return 0; } x = x * (C / g) % B; c[1] = c[1] + x * A; d[1] = A / g * B; c[1] %= d[1]; if (c[1] < 0) c[1] += d[1]; } c[1] += ceil(1.0 * (minx - c[1]) / d[1]); pus(check(c[1]), 2); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 40000 + 10; const int maxn = 100 + 10; const int MOD = 1000000007; const int DEBUG = 0; inline int inc(int a, int b) { return (a + b >= MOD) ? (a + b - MOD) : (a + b); } inline int dec(int a, int b) { return (a >= b) ? (a - b) : (a + MOD - b); } inline int mul(int a, int b) { return 1LL * a * b % MOD; } inline int power(int x, long long k) { int tmp = 1; while (k) { if (k & 1) tmp = mul(tmp, x); x = mul(x, x); k >>= 1; } return tmp; } long long gcd(long long a, long long b) { return (!b) ? (a) : (gcd(b, a % b)); } int n, pcnt, p[N]; bool isp[N]; inline void prepare(int N) { isp[0] = isp[1] = 1; for (int i = 2; i <= N; i++) { if (!isp[i]) p[++pcnt] = i; for (int j = 1; j <= pcnt && i * p[j] <= N; j++) { isp[i * p[j]] = 1; if (i % p[j] == 0) break; } } } struct data { pair<int, long long> pri[4050]; int cnt; inline void input() { int x; scanf("%d", &x); cnt = 0; for (int i = 1; i <= pcnt && x >= p[i]; i++) { if (x % p[i]) continue; pair<int, long long> now = make_pair(p[i], 0); while (x % p[i] == 0) { now.second++; x /= p[i]; } cnt++; pri[cnt] = now; } if (x > 1) pri[++cnt] = make_pair(x, 1); } inline pair<int, long long> query(int x) { for (int i = 1; i <= cnt; i++) if (pri[i].first == x) return pri[i]; return make_pair(x, 0); } } a[maxn], b[maxn]; int lis[N], tot; inline void init(data a) { for (int i = 1; i <= a.cnt; i++) lis[++tot] = a.pri[i].first; } pair<int, long long> A1[N], A2[N], B1[N], B2[N]; inline int get_x(long long A, long long B, long long C, long long a, long long b, long long c, long long &x1, long long &x2) { while (a) { long long tmp = A / a; A -= tmp * a; B -= tmp * b; C -= tmp * c; swap(A, a); swap(B, b); swap(C, c); } if (abs(c) % abs(b)) return 0; x2 = -c / b; if (x2 < 0) return 0; if (abs(B * x2 + C) % A) return 0; x1 = (-B * x2 - C) / A; if (x1 < 0) return 0; return 1; } long long exgcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1, y = 0; return a; } long long g = exgcd(b, a % b, y, x); y -= a / b * x; return g; } inline int merge(int x, int y) { tot = 0; init(a[x]); init(a[y]); init(b[x]); init(b[y]); sort(lis + 1, lis + tot + 1); tot = unique(lis + 1, lis + tot + 1) - lis - 1; for (int i = 1; i <= tot; i++) A1[i] = a[x].query(lis[i]); for (int i = 1; i <= tot; i++) A2[i] = a[y].query(lis[i]); for (int i = 1; i <= tot; i++) B1[i] = b[x].query(lis[i]); for (int i = 1; i <= tot; i++) B2[i] = b[y].query(lis[i]); long long A, B, C, x1, x2; int flag = 0; A = B = C = x1 = x2 = 0; for (int i = 1; i <= tot; i++) { long long a = B1[i].second, b = -B2[i].second, c = A1[i].second - A2[i].second; if (DEBUG) printf("a b c %d %d %d\n", a, b, c); if (a == 0 && b == 0) { if (c == 0) continue; return 0; } long long g = gcd(a, gcd(-b, abs(c))); a /= g, b /= g, c /= g; if (!b && (c % a || -c / a < 0)) return 0; if (!A && !B && !C) { A = a; B = b; C = c; continue; } if (A * b == a * B && A * c == a * C) continue; if (A * b == a * B && A * c != a * C) return 0; if (!get_x(A, B, C, a, b, c, x1, x2)) return 0; flag = 1; break; } if (flag) { for (int i = 1; i <= tot; i++) { long long a = B1[i].second, b = -B2[i].second, c = A1[i].second - A2[i].second; if (a * x1 + b * x2 + c) return 0; A1[i].second += x1 * B1[i].second; B1[i].second = 0; } for (int i = 1; i <= tot; i++) a[x].pri[i] = A1[i], b[x].pri[i] = B1[i]; a[x].cnt = b[x].cnt = tot; return 1; } long long g = exgcd(A, B, x1, x2); if (C % g) return 0; x1 *= -C / g, x2 *= -C / g; long long t1 = abs(B / g), t2 = abs(A / g); if (C > 0 || !t2) { x1 = (x1 % t1 + t1) % t1; if (B) x2 = (-C - A * x1) / B; else x2 = 0; } else { x2 = (x2 % t2 + t2) % t2; if (A) x1 = (-C - B * x2) / A; else x1 = 0; } for (int i = 1; i <= tot; i++) { A1[i].second += B1[i].second * x1; B1[i].second *= t1; } for (int i = 1; i <= tot; i++) a[x].pri[i] = A1[i], b[x].pri[i] = B1[i]; a[x].cnt = b[x].cnt = tot; return 1; } int main() { prepare(40000); scanf("%d", &n); for (int i = 1; i <= n; i++) a[i].input(), b[i].input(); int bo = 1; for (int i = 2; i <= n && bo; i++) { bo &= merge(1, i); } if (!bo) { puts("-1"); return 0; } int Ans = 1; for (int i = 1; i <= a[1].cnt; i++) { Ans = mul(Ans, power(a[1].pri[i].first, a[1].pri[i].second)); } printf("%d\n", Ans); return 0; }
#include <bits/stdc++.h> using namespace std; map<int, int> id; int dy[505]; int idc; struct fuck { long long ori[550]; long long delta[550]; } seq[105]; const int mod = 1000000007; int qpow(long long base, long long tms) { long long tmp = 1; while (tms) { if (tms & 1) tmp = tmp * base % mod; base = base * base % mod; tms >>= 1; } return tmp; } long long x, y; long long exgcd(long long a, long long b) { if (b == 0) { x = 1, y = 0; return a; } long long gc = exgcd(b, a % b); long long t = x; x = y; y = t - a / b * x; return gc; } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { int a, b; scanf("%d%d", &a, &b); for (int j = 2; j * j <= a; ++j) { if (a % j == 0) { if (!id[j]) id[j] = ++idc, dy[idc] = j; while (a % j == 0) seq[i].ori[id[j]]++, a /= j; } } if (a > 1) { if (!id[a]) id[a] = ++idc, dy[idc] = a; seq[i].ori[id[a]]++; } for (int j = 2; j * j <= b; ++j) { if (b % j == 0) { if (!id[j]) id[j] = ++idc, dy[idc] = j; while (b % j == 0) seq[i].delta[id[j]]++, b /= j; } } if (b > 1) { if (!id[b]) id[b] = ++idc, dy[idc] = b; seq[i].delta[id[b]]++; } } for (int i = 2; i <= n; ++i) { int ps = 0; for (int j = 1; j <= idc; ++j) if (seq[1].delta[j] || seq[i].delta[j]) { ps = j; break; } if (!ps) { for (int j = 1; j <= idc; ++j) if (seq[1].ori[j] != seq[i].ori[j]) { printf("-1\n"); return 0; } continue; } int nxt = 0; for (int j = ps + 1; j <= idc; ++j) if (seq[i].delta[ps] * seq[1].delta[j] == seq[i].delta[j] * seq[1].delta[ps] && (seq[1].ori[ps] - seq[i].ori[ps]) * seq[i].delta[j] == (seq[1].ori[j] - seq[i].ori[j]) * seq[i].delta[ps]) ; else { nxt = j; break; } if (!nxt) { long long a = seq[1].delta[ps], b = -seq[i].delta[ps], c = seq[i].ori[ps] - seq[1].ori[ps]; long long gc1 = abs(exgcd(exgcd(a, b), c)); a /= gc1, b /= gc1, c /= gc1; long long gc = exgcd(a, b); if (c % gc) { printf("-1\n"); return 0; } x *= c / gc; y *= c / gc; b = -b; long long pl, tm; if ((a == 0 && y < 0) || (b == 0 && x < 0)) { printf("-1\n"); return 0; } else if (a == 0) pl = tm = 0; else if (b == 0) pl = x, tm = 0; else { long long t = max(-(y / a), -(x / b)); x += t * b; y += t * a; while (x < 0 || y < 0) x += b, y += a; while (x >= b && y >= a) x -= b, y -= a; pl = x, tm = b; } for (int j = 1; j <= idc; ++j) seq[1].ori[j] += seq[1].delta[j] * pl, seq[1].delta[j] *= tm; } else { long long a = seq[1].delta[ps], b = seq[i].delta[ps], c = seq[i].ori[ps] - seq[1].ori[ps]; long long d = seq[1].delta[nxt], e = seq[i].delta[nxt], f = seq[i].ori[nxt] - seq[1].ori[nxt]; x = b * f - e * c; y = a * f - d * c; long long m = b * d - a * e; if (!m || x % m || y % m) { printf("-1\n"); return 0; } x /= m; y /= m; if (x < 0 || y < 0) { printf("-1\n"); return 0; } for (int j = 1; j <= idc; ++j) if (seq[1].ori[j] + seq[1].delta[j] * x != seq[i].ori[j] + seq[i].delta[j] * y) { printf("-1\n"); return 0; } else seq[1].ori[j] = seq[1].ori[j] + seq[1].delta[j] * x, seq[1].delta[j] = 0; } } long long ans = 1; for (int i = 1; i <= idc; ++i) ans = ans * qpow(dy[i], seq[1].ori[i]) % mod; printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long power(long long x, long long y) { long long re = 1; while (y) { if (y & 1) re = re * x % mod; x = x * x % mod; y >>= 1; } return re; } long long mul(long long x, long long y, long long mod) { if (y < 0) { x = -x; y = -x; } long long re = 0; while (y) { if (y & 1) re = (re + x) % mod; x = (x << 1) % mod; y >>= 1; } return re; } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return a; } int d = exgcd(b, a % b, y, x); y -= a / b * x; return d; } long long lcm(long long a, long long b) { long long d = gcd(a, b); return a / d * b; } long long inver(long long a, long long b) { long long x, y; exgcd(a, b, x, y); x = (x % b + b) % b; return x; } int ord(int a, int p) { int re = 0; while (a % p == 0) { ++re; a /= p; } return re; } vector<int> Merge(const vector<int> &a, const vector<int> &b) { vector<int> re(a.size() + b.size()); merge(a.begin(), a.end(), b.begin(), b.end(), re.begin()); re.resize(unique(re.begin(), re.end()) - re.begin()); return re; } struct AP { long long s, t; AP(long long s = -1, long long t = -1) : s(s), t(t) {} void print() { cerr << s << ' ' << t << endl; } }; AP trace(AP A, AP B) { return AP((A.s - B.s) / B.t, A.t / B.t); } AP subsec(AP A, AP B) { return AP(A.s + B.s * A.t, A.t * B.t); } AP intersect(AP A, AP B) { if (A.s == -1 || B.s == -1) { return AP(); } if (A.t == 0 && B.t == 0) { if (A.s == B.s) { return A; } return AP(); } if (B.t == 0) { swap(A, B); } if (A.t == 0) { if (A.s >= B.s && (A.s - B.s) % B.t == 0) { return A; } return AP(); } long long d = gcd(A.t, B.t); if (A.s % d != B.s % d) { return AP(); } if (A.s < B.s) { swap(A, B); } long long a = A.t / d; long long b = B.t / d; long long c = (B.s - A.s) / d; long long y = mul((-c) % a, inver(b, a), a); y += a * max(0LL, (-c - y * b + a * b - 1) / (a * b)); return AP(B.s + B.t * y, lcm(A.t, B.t)); } AP strong_intersect(AP a, AP b) { if (a.t == b.t) { if (a.s == b.s) return a; return AP(); } if (a.s == b.s) { return AP(a.s, 0); } if (a.s < b.s) { swap(a, b); } long long num = (a.s - b.s); long long den = (b.t - a.t); if (den < 0 || num % den) { return AP(); } num /= den; return AP(a.s + a.t * num, 0); } long long fix(int A0, int B0, long long fix0, int A1, int B1, const vector<int> p, bool &flag) { long long fix = -1; for (unsigned int i = 0; i < p.size(); ++i) { int P = p[i]; AP A(ord(A0, P), ord(B0, P)); if (fix0 != -1) { A.s += A.t * fix0; A.t = 0; } AP B(ord(A1, P), ord(B1, P)); AP I = intersect(A, B); if (I.s == -1) { flag = true; return -1; } if (I.t == 0 && B.t != 0) { long long nfix = (I.s - B.s) / B.t; if (fix != -1 && fix != nfix) { flag = true; return -1; } fix = nfix; } } return fix; } AP calc(int A0, int B0, int A1, int B1, const vector<int> &p) { bool flag = 0; long long fix0, fix1; fix1 = fix(A0, B0, -1, A1, B1, p, flag); fix0 = fix(A1, B1, fix1, A0, B0, p, flag); fix1 = fix(A0, B0, fix0, A1, B1, p, flag); if (flag) { return AP(); } if (fix0 != -1) { return AP(fix0, 0); } AP I0(0, 1); AP I1(0, 1); bool was = false; for (unsigned int i = 0; i < p.size(); ++i) { int P = p[i]; AP A(ord(A0, P), ord(B0, P)); AP B(ord(A1, P), ord(B1, P)); AP I = intersect(A, B); if (A.t == 0 || B.t == 0) { continue; } AP AA = trace(I, A); AP BB = trace(I, B); if (!was) { was = 1; I0 = AA; I1 = BB; continue; } AP X = intersect(AA, I0); AP Y = intersect(BB, I1); if (X.s == -1 || Y.s == -1) { return AP(); } AP subold0 = trace(X, I0); AP subold1 = trace(Y, I1); AP subold2 = intersect(subold0, subold1); if (subold2.s == -1) { return AP(); } I0 = subsec(I0, subold2); I1 = subsec(I1, subold2); AP subnew0 = trace(I0, AA); AP subnew1 = trace(I1, BB); AP subnew2 = strong_intersect(subnew0, subnew1); if (subnew2.s == -1) { return AP(); } I0 = subsec(AA, subnew2); I1 = subsec(BB, subnew2); if (I1.t == 0) { fix1 = I1.s; fix0 = fix(A1, B1, fix1, A0, B0, p, flag); if (flag) { return AP(); } I0 = AP(fix0, 0); } if (I0.t == 0) { fix0 = I0.s; fix1 = fix(A0, B0, fix0, A1, B1, p, flag); if (flag) { return AP(); } return AP(fix0, 0); } } return I0; } int n; int a[105], b[105]; vector<int> p[105]; bool check(int a, int b, int x) { if (x % a) { return false; } x /= a; if (b == 1) { return x == 1; } while (x > 1) { if (x % b) { return false; } x /= b; } return x == 1; } vector<int> getprime(int n) { vector<int> p; for (int i = 2; i <= n / i; ++i) if (n % i == 0) { p.push_back(i); while (n % i == 0) { n /= i; } } if (n > 1) { p.push_back(n); } return p; } int solve() { for (int i = 1; i <= n; ++i) if (b[i] == 1) { for (int j = 1; j <= n; ++j) { if (!check(a[j], b[j], a[i])) return -1; } return a[i]; } for (int i = 1; i <= n; ++i) { p[i] = Merge(getprime(a[i]), getprime(b[i])); } AP I(0, 1); for (int i = 2; i <= n; ++i) { vector<int> P = Merge(p[1], p[i]); I = intersect(I, calc(a[1], b[1], a[i], b[i], P)); if (I.s == -1) { return -1; } } return a[1] * power(b[1], I.s) % mod; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d", &a[i], &b[i]); } printf("%d\n", solve()); return 0; }
#include <bits/stdc++.h> template <class T1, class T2> inline bool cmin(T1 &a, const T2 &b) { return b < a ? (a = b, true) : false; } template <class T1, class T2> inline bool cmax(T1 &a, const T2 &b) { return a < b ? (a = b, true) : false; } template <class Type> Type read() { Type a; bool b; unsigned char c; while (c = getchar() - 48, (c > 9) & (c != 253)) ; for (a = (b = c == 253) ? 0 : c; (c = getchar() - 48) <= 9; a = a * 10 + c) ; return b ? -a : a; } auto rd = read<int>; void gg() { puts("-1"); exit(0); } long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return a; } long long d = exgcd(b, a % b, y, x); y -= a / b * x; return d; } struct Rem { long long r, d; Rem &operator&=(const Rem &o) { long long x, y, g = exgcd(d, o.d, x, y), rhs = o.r - r; if (rhs % g != 0) gg(); r += rhs * x % o.d * (d / g); d *= o.d / g; if (r < 0) r += d; return *this; } }; const int N = 100; int m, aval[N], bval[N]; std::valarray<long long> a[N], b[N]; std::vector<int> prime; void gl(std::valarray<long long> x) { const unsigned P = 1e9 + 7; unsigned ans = 1; for (int i = 0; i < m; ++i) { unsigned long long b = prime[i]; for (int e = x[i] % (P - 1); e; b = b * b % P, e >>= 1) if (e & 1) ans = ans * b % P; } printf("%u\n", ans); exit(0); } long long ddiv(long long a, long long b) { if (b == 0) { if (a != 0) gg(); return -1; } if (a % b != 0) gg(); a /= b; if (a < 0) gg(); return a; } long long ddiv(std::valarray<long long> a, std::valarray<long long> b) { long long res = -1; for (int i = 0; i < m; ++i) { long long v = ddiv(a[i], b[i]); if (v == -1) continue; if (res != v && res != -1) gg(); res = v; } return res; } void extract(int n) { for (auto p : prime) while (n % p == 0) n /= p; for (int p = 2; 1ll * p * p <= n; ++p) if (n % p == 0) { while (n % p == 0) n /= p; prime.push_back(p); } if (n > 1) prime.push_back(n); } std::valarray<long long> factor(int n) { std::valarray<long long> res(m); for (int i = 0; i < m; ++i) { int p = prime[i]; while (n % p == 0) ++res[i], n /= p; } return res; } int main() { int n = rd(); for (int i = 0; i < n; ++i) extract(aval[i] = rd()), extract(bval[i] = rd()); m = prime.size(); for (int i = 0; i < n; ++i) a[i] = factor(aval[i]), b[i] = factor(bval[i]); for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) if (b[j][i] == 0) { for (int k = 0; k < n; ++k) { long long nk = ddiv(a[j][i] - a[k][i], b[k][i]); if (nk != -1) { std::valarray<long long> x = a[k] + nk * b[k]; for (int l = 0; l < n; ++l) ddiv(x - a[l], b[l]); gl(x); } } break; } int k = 0; while (k < m && b[0][k] == 0) ++k; if (k == m) gl(a[0]); for (int i = k + 1; i < m; ++i) if (b[0][i] != 0) for (int j = 1; j < n; ++j) { long long n0 = ddiv((a[j][i] - a[0][i]) * b[j][k] - (a[j][k] - a[0][k]) * b[j][i], b[0][i] * b[j][k] - b[0][k] * b[j][i]); if (n0 != -1) { std::valarray<long long> x = a[0] + n0 * b[0]; for (int l = 0; l < n; ++l) ddiv(x - a[l], b[l]); gl(x); } } Rem ans = {0, 1}; for (int i = 0; i < n; ++i) ans &= {a[i][k] % b[i][k], b[i][k]}; for (int i = 0; i < n; ++i) if (ans.r < a[i][k]) ans.r += ((a[i][k] - ans.r - 1) / ans.d + 1) * ans.d; gl(a[0] + (ans.r - a[0][k]) / b[0][k] * b[0]); return 0; }
#include <bits/stdc++.h> using namespace std; struct pp { int a, b; }; pp pt[111]; int n, fac[211111], num_fac, num, num_row, aa[2111][102], bb[2111][102]; long long now_ex[111]; const int mod = 1e9 + 7; bool vis[111]; long long x, y, d, now_a, now_b, ep[2111]; int ans; void gcd(long long a, long long n) { long long temp; if (n == 0) { d = a; x = 1; y = 0; return; } gcd(n, a % n); temp = x; x = y; y = temp - (a / n) * y; } int power(int a, long long n) { int res; if (n == 0) return 1; res = power(a, n / 2); res = (int)((long long)res * (long long)res % mod); if (n % 2) res = (int)((long long)res * (long long)a % mod); return res; } int main() { int i, j, s, p, q, tmp, a, b, v1, v2; bool add; scanf("%d", &n); num_fac = 0; for (i = 0; i < n; i++) { scanf("%d%d", &pt[i].a, &pt[i].b); for (s = 0; s < 2; s++) { a = pt[i].a; if (s == 1) a = pt[i].b; for (j = 2; j * j <= a; j++) { if (a % j == 0) { fac[num_fac++] = j; while (a % j == 0) a /= j; } } if (a > 1) fac[num_fac++] = a; } } sort(fac, fac + num_fac); num = 0; for (i = 0; i < num_fac; i++) { if (num == 0 || fac[num - 1] != fac[i]) fac[num++] = fac[i]; } num_fac = num; memset(now_ex, -1, sizeof(now_ex)); num_row = 0; memset(aa, 0, sizeof(aa)); memset(bb, 0, sizeof(bb)); for (i = 0; i < num_fac; i++) { for (j = 0; j < n; j++) { a = pt[j].a; while (a % fac[i] == 0) { a /= fac[i]; bb[num_row][j]++; } b = pt[j].b; while (b % fac[i] == 0) { b /= fac[i]; aa[num_row][j]++; } } for (j = 0; j < n; j++) { for (s = 0; s < n; s++) { if (aa[num_row][s] == 0 && aa[num_row][j] != 0) { a = aa[num_row][j]; b = bb[num_row][s] - bb[num_row][j]; if (b % a != 0 || b < 0) { puts("-1"); return 0; } v1 = b / a; if (now_ex[j] >= 0 && now_ex[j] != v1) { puts("-1"); return 0; } if (now_ex[j] < 0) now_ex[j] = v1; } if (aa[num_row][s] == 0 && aa[num_row][j] == 0) { if (bb[num_row][s] != bb[num_row][j]) { puts("-1"); return 0; } } } } if (num_row >= 1) { for (j = 0; j < n; j++) { for (s = 0; s < n; s++) { if (j == s) continue; if (aa[num_row][j] != 0 || aa[num_row][s] != 0) { for (p = num_row - 1; p >= 0; p--) { if (aa[p][j] != 0 || aa[p][s] != 0) break; } if (p < 0) continue; } else { if (bb[num_row][j] != bb[num_row][s]) { puts("-1"); return 0; } continue; } a = aa[num_row][j] * aa[p][s] - aa[p][j] * aa[num_row][s]; b = (bb[num_row][s] - bb[num_row][j]) * aa[p][s] - (bb[p][s] - bb[p][j]) * aa[num_row][s]; if ((a == 0 && b != 0) || (a != 0 && b % a != 0) || (a != 0 && b / a < 0)) { puts("-1"); return 0; } if (a != 0) { v1 = b / a; b = (bb[p][j] - bb[p][s]) * aa[num_row][j] - (bb[num_row][j] - bb[num_row][s]) * aa[p][j]; if (b % a != 0 || b / a < 0) { puts("-1"); return 0; } v2 = b / a; if ((now_ex[j] >= 0 && now_ex[j] != v1) || (now_ex[s] >= 0 && now_ex[s] != v2)) { puts("-1"); return 0; } if (now_ex[j] < 0) now_ex[j] = v1; if (now_ex[s] < 0) now_ex[s] = v2; } } } } num_row++; } if (now_ex[0] < 0) { memset(vis, false, sizeof(vis)); for (j = 0; j < num_fac; j++) { now_a = 1; now_b = 0; for (i = 0; i < n; i++) { if (aa[j][i] == 0) continue; gcd(now_a, aa[j][i]); now_b = bb[j][i] - now_b; if (now_b % d != 0) { puts("-1"); return 0; } x = (long long)x * (long long)(now_b / d) % (aa[j][i] / d); if (x < 0) x += aa[j][i]; now_b = bb[j][i] - now_b; now_b = (x * now_a + now_b) % (now_a * (aa[j][i] / d)); now_a = now_a * (aa[j][i] / d); } for (i = 0; i < n; i++) { while (now_b < bb[j][i]) now_b += now_a; } ep[j] = now_b; } } else { memset(ep, 0, sizeof(ep)); for (j = 0; j < num_fac; j++) { for (i = 0; i < n; i++) { if (now_ex[i] >= 0) { ep[j] = now_ex[i] * aa[j][i] + bb[j][i]; break; } } } } ans = 1; for (i = 0; i < num_fac; i++) ans = (int)((long long)ans * (long long)power(fac[i], ep[i]) % mod); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int p[110][60], t[110], a[110][60], d[110][60], n, rp[60], T; long long rq[60]; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int qpow(long long a, long long i) { long long r = 1; for (; i; i >>= 1, a = a * a % 1000000007) if (i & 1) r = r * a % 1000000007; return r; } void check() { for (int i = 1; i <= n; ++i) { long long TMP = -1; for (int j = 1, k = 1; j <= t[i]; ++j) { while (k <= T && p[i][j] > rp[k]) { if (rq[k]) { printf("-1"); exit(0); }; ++k; } if (k > T || rp[k] ^ p[i][j]) { if (a[i][j]) { printf("-1"); exit(0); }; if (TMP < 0) TMP = 0; else if (TMP) { printf("-1"); exit(0); }; --k; } else if (d[i][j]) { if ((rq[k] - a[i][j]) % d[i][j]) { printf("-1"); exit(0); }; long long R = (rq[k] - a[i][j]) / d[i][j]; if (R < 0) { printf("-1"); exit(0); }; if (TMP < 0) TMP = R; else if (TMP ^ R) { printf("-1"); exit(0); }; } else if (a[i][j] ^ rq[k]) { printf("-1"); exit(0); }; ++k; } } long long ans = 1; for (int i = 1; i <= T; ++i) ans = qpow(rp[i], rq[i]) * ans % 1000000007; printf("%I64d", ans); exit(0); } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { int A, Q; scanf("%d %d", &A, &Q); for (int j = 2; j <= 32000; ++j) { if (A == 1 && Q == 1) break; if (j * j > A && j * j > Q) { if (A == Q) p[i][++t[i]] = A, a[i][t[i]] = d[i][t[i]] = 1; if (A ^ 1) if (A < Q || Q == 1) p[i][++t[i]] = A, a[i][t[i]] = 1; if (Q ^ 1) if (A > Q || A == 1) p[i][++t[i]] = Q, d[i][t[i]] = 1; if (A < Q && A ^ 1) p[i][++t[i]] = Q, d[i][t[i]] = 1; if (A > Q && Q ^ 1) p[i][++t[i]] = A, a[i][t[i]] = 1; A = Q = 1; } if (A == 1 && Q == 1) break; if (A % j == 0 || Q % j == 0) { ++t[i]; p[i][t[i]] = j; while (A % j == 0) A /= j, ++a[i][t[i]]; while (Q % j == 0) Q /= j, ++d[i][t[i]]; } } } for (int i = 2; i <= n; ++i) { for (int j = 1; j <= t[i] || j <= t[1]; ++j) if (p[i][j] < p[1][j] || !p[1][j]) { if (a[i][j]) { printf("-1"); exit(0); }; T = t[i]; for (int k = 1; k <= t[i]; ++k) rq[k] = a[i][k], rp[k] = p[i][k]; check(); } else if (p[1][j] < p[i][j] || !p[i][j]) { if (a[1][j]) { printf("-1"); exit(0); }; T = t[1]; for (int k = 1; k <= t[1]; ++k) rq[k] = a[1][k], rp[k] = p[1][k]; check(); } else if (d[i][j] && !d[1][j]) { if ((a[1][j] - a[i][j]) % d[i][j] != 0) { printf("-1"); exit(0); }; int D = (a[1][j] - a[i][j]) / d[i][j]; if (D < 0) { printf("-1"); exit(0); }; T = t[i]; for (int k = 1; k <= t[i]; ++k) rq[k] = a[i][k] + d[i][k] * D, rp[k] = p[i][k]; check(); } else if (d[1][j] && !d[i][j]) { if ((a[i][j] - a[1][j]) % d[1][j] != 0) { printf("-1"); exit(0); }; int D = (a[i][j] - a[1][j]) / d[1][j]; if (D < 0) { printf("-1"); exit(0); }; T = t[1]; for (int k = 1; k <= t[1]; ++k) rq[k] = a[1][k] + d[1][k] * D, rp[k] = p[1][k]; check(); } else if (!d[i][j] && !d[1][j]) if (a[i][j] ^ a[1][j]) { printf("-1"); exit(0); }; for (int j = 2; j <= t[i]; ++j) if (d[1][1] * d[i][j] ^ d[1][j] * d[i][1]) { for (int x = 0; x <= 30; ++x) for (int y = 0; y <= 30; ++y) if (a[1][1] + d[1][1] * x == a[i][1] + d[i][1] * y) if (a[1][j] + d[1][j] * x == a[i][j] + d[i][j] * y) { for (int k = 1; k <= t[i]; ++k) rq[k] = a[1][k] + d[1][k] * x, rp[k] = p[1][k]; T = t[1]; check(); } { printf("-1"); exit(0); }; } } long long A = 0, Q = 1; for (int i = 2; i <= n; ++i) for (int j = 1; j <= t[1]; ++j) if (d[i][j] || d[1][j]) { int B = -1, P = d[i][j] / gcd(d[i][j], d[1][j]), t = 0; for (int k = 0; k < 60; ++k) if (d[1][j] * k + a[1][j] >= a[i][j]) if ((d[1][j] * k + a[1][j] - a[i][j]) % d[i][j] == 0) { B = k; break; } if (B < 0) { printf("-1"); exit(0); }; for (int k = 0; k < 90; ++k) if (Q * k + A >= B) if ((Q * k + A - B) % P == 0) { t = 1; A = Q * k + A; Q = Q * P / gcd(P, Q); break; } if (!t) { printf("-1"); exit(0); }; } T = t[1]; for (int i = 1; i <= t[1]; ++i) rp[i] = p[1][i], rq[i] = A * d[1][i] + a[1][i]; check(); }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; inline int ksm(int x, long long y) { int res = 1; while (y > 0) { if (y & 1) res = 1ll * res * x % MOD; x = 1ll * x * x % MOD; y >>= 1; } return res; } long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return a; } long long gcd1 = exgcd(b, a % b, x, y); long long t = x; x = y, y = t - a / b * y; return gcd1; } long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } int n, a[105], b[105], pri[2005], m; struct node { long long a[2005], b[2005]; bool merge(node x) { long long sum1 = 0, sum2 = 0; for (int i = 1; i <= m; i++) sum1 += b[i], sum2 += x.b[i]; if (sum1 == 0 && sum2 == 0) { for (int i = 1; i <= m; i++) if (a[i] != x.a[i]) return 0; return 1; } if (sum1 == 0 || sum2 == 0) { if (sum2 == 0) { swap(a, x.a); swap(b, x.b); swap(sum1, sum2); } long long res = 0; for (int i = 1; i <= m; i++) if (x.b[i] != 0) { res = ((a[i] >= x.a[i]) && ((a[i] - x.a[i]) % x.b[i] == 0)) ? (a[i] - x.a[i]) / x.b[i] : -1; break; } else if (a[i] != x.a[i]) return 0; if (res == -1) return 0; for (int i = 1; i <= m; i++) if ((x.a[i] + res * x.b[i]) != a[i]) return 0; return 1; } long long sta = -1; for (int i = 1; i <= m; i++) if (b[i] * sum2 != x.b[i] * sum1) { sta = i; break; } if (sta == -1) { long long b1 = 0, b2 = 0, gcd1; for (int i = 1; i <= m; i++) if (b[i] != 0) { gcd1 = gcd(b[i], x.b[i]); b1 = b[i] / gcd1; b2 = x.b[i] / gcd1; break; } long long res = 0; for (int i = 1; i <= m; i++) if (b[i] != 0) { if ((a[i] - x.a[i]) % gcd1) return 0; res = (a[i] - x.a[i]) / gcd1; break; } for (int i = 1; i <= m; i++) if ((x.a[i] + res * gcd1) != a[i]) return 0; if (res < 0) { swap(a, x.a); swap(b, x.b); swap(b1, b2); res = -res; } long long xx, yy; exgcd(b1, b2, xx, yy); res = -res; xx = (xx * res % b2 + b2) % b2; for (int i = 1; i <= m; i++) a[i] += xx * b[i], b[i] *= b2; } else { long long p1 = sta, p2 = 0; for (int i = 1; i <= m; i++) if (b[p1] * x.b[i] != x.b[p1] * b[i]) { p2 = i; break; } long long xx = x.b[p2] * (x.a[p1] - a[p1]) - x.b[p1] * (x.a[p2] - a[p2]); long long yy = b[p2] * (x.a[p1] - a[p1]) - b[p1] * (x.a[p2] - a[p2]); long long fenm = x.b[p2] * b[p1] - b[p2] * x.b[p1]; if (fenm < 0) xx = -xx, yy = -yy, fenm = -fenm; if (xx < 0 || yy < 0 || xx % fenm != 0 || yy % fenm != 0) return 0; xx /= fenm, yy /= fenm; for (int i = 1; i <= m; i++) { if ((a[i] + xx * b[i]) != (x.a[i] + yy * x.b[i])) return 0; a[i] += xx * b[i]; b[i] = 0; } } return 1; } } s[105]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i], &b[i]); int a1 = a[i], b1 = b[i]; for (int j = 2; j * j <= a[i]; j++) if (a1 % j == 0) { pri[++m] = j; while (a1 % j == 0) a1 /= j; } if (a1 != 1) pri[++m] = a1; for (int j = 2; j * j <= b[i]; j++) if (b1 % j == 0) { pri[++m] = j; while (b1 % j == 0) b1 /= j; } if (b1 != 1) pri[++m] = b1; } sort(pri + 1, pri + m + 1); m = unique(pri + 1, pri + m + 1) - pri - 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) while (a[i] % pri[j] == 0) a[i] /= pri[j], s[i].a[j]++; for (int j = 1; j <= m; j++) while (b[i] % pri[j] == 0) b[i] /= pri[j], s[i].b[j]++; } for (int i = 2; i <= n; i++) if (!s[i].merge(s[i - 1])) return printf("-1"), 0; int ans = 1; for (int i = 1; i <= m; i++) ans = 1ll * ans * ksm(pri[i], s[n].a[i]) % MOD; printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1e9 + 7; long long mult(long long a, long long b, long long mod) { return (a * b) % mod; } long long pw(long long a, long long b) { if (b == 0) return 1; if (b & 1) return mult(a, pw(a, b - 1), mod); long long res = pw(a, b / 2); return mult(res, res, mod); } long long inv(long long a, long long b) { if (a == 0) return 0; if (a == 1) return 1; if (a >= b) return inv(a % b, b); return mult(b - inv(b % a, b), b / a, b); } long long gcd(long long a, long long b) { while (a > 0 && b > 0) { if (a < b) swap(a, b); a %= b; } return a + b; } void no() { cout << -1; exit(0); } const int maxN = 105; int n, k; int a[maxN], b[maxN], copa[maxN], copb[maxN]; vector<int> primes; vector<int> valA[maxN]; vector<int> valB[maxN]; vector<bool> skip; vector<int> nvalA[maxN], nvalB[maxN]; void go(int p) { for (int i = 1; i <= n; i++) { int exp = 0; while (a[i] % p == 0) { a[i] /= p; exp++; } valA[i].push_back(exp); exp = 0; while (b[i] % p == 0) { b[i] /= p; exp++; } valB[i].push_back(exp); } } void can(int ind, long long t) { vector<long long> vals; vals.resize(k); for (int i = 0; i < k; i++) { vals[i] = t * valB[ind][i] + valA[ind][i]; } for (int i = 1; i <= n; i++) { int t = -1; for (int j = 0; j < k; j++) { if (t != -1) { if (valA[i][j] + t * valB[i][j] != vals[j]) no(); } else { if (valB[i][j] == 0) { if (valA[i][j] != vals[j]) no(); } else { if (valA[i][j] > vals[j]) no(); if ((vals[j] - valA[i][j]) % valB[i][j] != 0) no(); t = (vals[j] - valA[i][j]) / valB[i][j]; } } } } cout << mult(copa[ind], pw(copb[ind], t), mod); exit(0); } pair<long long, long long> unite(pair<long long, long long> a, pair<long long, long long> b) { long long a1 = a.first; long long a2 = b.first; long long b1 = a.second; long long b2 = b.second; long long dif = a2 - a1; long long cop = b1; dif = (dif % b2 + b2) % b2; long long d = gcd(b1, b2); if (dif % d != 0) { no(); } b1 /= d; dif /= d; b2 /= d; long long x = mult(dif, inv(b1, b2), b2); long long nx = x * cop + a1; return make_pair(nx, cop * b2); } int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; copa[i] = a[i]; copb[i] = b[i]; } for (int i = 1; i <= n; i++) { for (int j = 2; 1LL * j * j <= a[i]; j++) { if (a[i] % j == 0) { go(j); } } if (a[i] > 1) go(a[i]); for (int j = 2; 1LL * j * j <= b[i]; j++) { if (b[i] % j == 0) { go(j); } } if (b[i] > 1) go(b[i]); } k = valA[1].size(); skip.resize(k, false); for (int i = 0; i < k; i++) { int zero = -1; int nonzero = -1; for (int j = 1; j <= n; j++) { if (valB[j][i] == 0) zero = j; if (valB[j][i] != 0) nonzero = j; } if (nonzero == -1) { for (int j = 1; j <= n; j++) { if (valA[j][i] != valA[1][i]) no(); } skip[i] = true; } else if (zero != -1) { int finalval = valA[zero][i]; finalval -= valA[nonzero][i]; if (finalval < 0) no(); if (finalval % valB[nonzero][i] != 0) no(); int t = finalval / valB[nonzero][i]; can(nonzero, t); } } for (int i = 1; i <= n; i++) { for (int j = 0; j < k; j++) { if (skip[j]) continue; nvalA[i].push_back(valA[i][j]); nvalB[i].push_back(valB[i][j]); } valA[i] = nvalA[i]; valB[i] = nvalB[i]; } if (valA[1].size() == 0) { cout << copa[1]; exit(0); } k = valA[1].size(); for (int i = 2; i <= n; i++) { for (int j = 1; j < k; j++) { if (valB[1][0] * valB[i][j] != valB[1][j] * valB[i][0]) { int det1 = -valB[1][0] * valB[i][j] + valB[1][j] * valB[i][0]; int det2 = +(valA[i][j] - valA[1][j]) * valB[i][0] - valB[i][j] * (valA[i][0] - valA[1][0]); int det3 = +(valA[i][j] - valA[1][j]) * valB[1][0] - valB[1][j] * (valA[i][0] - valA[1][0]); int t1 = det2 / det1; if (det1 * t1 != det2) no(); if (t1 < 0) no(); can(1, t1); } if ((valB[1][0] * (valA[i][j] - valA[1][j]) - valB[1][j] * (valA[i][0] - valA[1][0])) != 0) no(); } } vector<pair<int, int> > conditions; long long limit = 0; for (int i = 2; i <= n; i++) { int x = valB[1][0]; int y = valA[i][0] - valA[1][0]; int mod = valB[i][0]; if (y >= 0) { limit = max(limit, (long long)(y + x - 1) / x); } y = (y % mod + mod) % mod; int d = gcd(x, mod); if (y % d != 0) no(); x /= d; mod /= d; y /= d; if (mod == 1) conditions.push_back(make_pair(0, 1)); else { int val = mult(y, inv(x, mod), mod); conditions.push_back(make_pair(val, mod)); } } if (conditions.size() == 0) { can(1, 0); } pair<long long, long long> cur = make_pair((long long)conditions[0].first, (long long)conditions[0].second); for (int i = 1; i < conditions.size(); i++) { cur = unite(cur, conditions[i]); } long long t = cur.first; if (cur.second == 1) t = limit; while (t < limit) t += cur.second; can(1, t); }
#include <bits/stdc++.h> using namespace std; inline int read(int f = 1, int x = 0, char ch = ' ') { while (!isdigit(ch = getchar())) if (ch == '-') f = -1; while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f * x; } const int N = 1e2 + 5, M = 3e3 + 5, P = 1e9 + 7; int n, m, a[N], b[N], p[M]; long long ca[M], cb[M], ans; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long exgcd(long long a, long long b, long long &x, long long &y, long long d = 0) { return b ? (d = exgcd(b, a % b, y, x), y -= a / b * x, d) : (x = 1, y = 0, a); } long long qpow(long long a, long long b) { long long c = 1; for (; b; b >>= 1, a = a * a % P) if (b & 1) c = c * a % P; return c; } int lg(int a, int b) { int c = 0; for (; b % a == 0; ++c, b /= a) ; return c; } void work(int n) { for (int i = 2; i * i <= n; ++i) if (n % i == 0) for (p[++m] = i; n % i == 0; n /= i) ; if (n != 1) p[++m] = n; } long long solve(long long A, long long B, long long C) { if (!A) return 0; if (!B) return C / A; long long x, y, d; exgcd(A, -B, x, y); x *= C, y *= -C, x %= -B, x += -B, x %= -B, y = (C - A * x) / B; if (y < 0) d = (-y + A - 1) / A, x += -B * d, y += A * d; return x; } void work(int a, int b) { bool fl1 = false, fl2 = false; long long x, y, A, B, C; for (int i = 1; i <= m; ++i) { long long _A = cb[i], _B = -lg(p[i], b), _C = lg(p[i], a) - ca[i], d = gcd(_A, -_B); if (!_A && !_B) (_C) ? (puts("-1"), exit(0)) : void(); else { (_C % d) ? (puts("-1"), exit(0)) : void(), _A /= d, _B /= d, _C /= d; if (fl2) (_A * x + _B * y != _C) ? (puts("-1"), exit(0)) : void(); else if (!fl1) fl1 = true, A = _A, B = _B, C = _C; else if (_A == A && _B == B) (_C != C) ? (puts("-1"), exit(0)) : void(); else { long long a = _A * B - _B * A, b = _C * B - _B * C; (b % a) ? (puts("-1"), exit(0)) : void(), x = b / a; a = _B * A - B * _A, b = _C * A - C * _A, (b % a) ? (puts("-1"), exit(0)) : void(), y = b / a; fl2 = true, (x < 0 || y < 0) ? (puts("-1"), exit(0)) : void(); } } } if (fl2) for (int i = 1; i <= m; ++i) ca[i] += x * cb[i], cb[i] = 0; else { long long x = solve(A, B, C); for (int i = 1; i <= m; ++i) ca[i] += x * cb[i], cb[i] *= -B; } } int main() { n = read(), ans = 1; for (int i = 1; i <= n; ++i) a[i] = read(), b[i] = read(), work(a[i]), work(b[i]); sort(p + 1, p + 1 + m), m = unique(p + 1, p + 1 + m) - p - 1; for (int i = 1; i <= m; ++i) ca[i] = lg(p[i], a[1]), cb[i] = lg(p[i], b[1]); for (int i = 2; i <= n; ++i) work(a[i], b[i]); for (int i = 1; i <= m; ++i) ans = ans * qpow(p[i], ca[i]) % P; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> template <class T1, class T2> inline bool cmin(T1 &a, const T2 &b) { return b < a ? (a = b, true) : false; } template <class T1, class T2> inline bool cmax(T1 &a, const T2 &b) { return a < b ? (a = b, true) : false; } template <class Type> Type read() { Type a; bool b; unsigned char c; while (c = getchar() - 48, (c > 9) & (c != 253)) ; for (a = (b = c == 253) ? 0 : c; (c = getchar() - 48) <= 9; a = a * 10 + c) ; return b ? -a : a; } auto rd = read<int>; void gg() { puts("-1"); exit(0); } long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return a; } long long d = exgcd(b, a % b, y, x); y -= a / b * x; return d; } struct Rem { long long r, d; Rem &operator&=(const Rem &o) { long long x, y, g = exgcd(d, o.d, x, y), rhs = o.r - r; if (rhs % g != 0) gg(); r += rhs * x % o.d * (d / g); d *= o.d / g; if (r < 0) r += d; return *this; } }; const int N = 100; int m, aval[N], bval[N]; std::valarray<long long> a[N], b[N]; std::vector<int> prime; void gl(std::valarray<long long> x) { const unsigned P = 1e9 + 7; unsigned ans = 1; for (int i = 0; i < m; ++i) { unsigned long long b = prime[i]; for (int e = x[i] % (P - 1); e; b = b * b % P, e >>= 1) if (e & 1) ans = ans * b % P; } printf("%u\n", ans); exit(0); } long long ddiv(long long a, long long b) { if (b == 0) { if (a != 0) gg(); return -1; } if (a % b != 0) gg(); a /= b; if (a < 0) gg(); return a; } long long ddiv(std::valarray<long long> a, std::valarray<long long> b) { long long res = -1; for (int i = 0; i < m; ++i) { long long v = ddiv(a[i], b[i]); if (v == -1) continue; if (res != v && res != -1) gg(); res = v; } return res; } void extract(int n) { for (auto p : prime) while (n % p == 0) n /= p; for (int p = 2; 1ll * p * p <= n; ++p) if (n % p == 0) { while (n % p == 0) n /= p; prime.push_back(p); } if (n > 1) prime.push_back(n); } std::valarray<long long> factor(int n) { std::valarray<long long> res(m); for (int i = 0; i < m; ++i) { int p = prime[i]; while (n % p == 0) ++res[i], n /= p; } return res; } int main() { int n = rd(); for (int i = 0; i < n; ++i) extract(aval[i] = rd()), extract(bval[i] = rd()); m = prime.size(); for (int i = 0; i < n; ++i) a[i] = factor(aval[i]), b[i] = factor(bval[i]); for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) if (b[j][i] == 0) { for (int k = 0; k < n; ++k) { long long nk = ddiv(a[j][i] - a[k][i], b[k][i]); if (nk != -1) { std::valarray<long long> x = a[k] + nk * b[k]; for (int l = 0; l < n; ++l) ddiv(x - a[l], b[l]); gl(x); } } break; } int k = 0; while (k < m && b[0][k] == 0) ++k; if (k == m) gl(a[0]); for (int i = k + 1; i < m; ++i) if (b[0][i] != 0) for (int j = 1; j < n; ++j) { long long n0 = ddiv((a[j][i] - a[0][i]) * b[j][k] - (a[j][k] - a[0][k]) * b[j][i], b[0][i] * b[j][k] - b[0][k] * b[j][i]); if (n0 != -1) { std::valarray<long long> x = a[0] + n0 * b[0]; for (int l = 0; l < n; ++l) ddiv(x - a[l], b[l]); gl(x); } } Rem ans = {0, 1}; for (int i = 0; i < n; ++i) ans &= {a[i][k] % b[i][k], b[i][k]}; for (int i = 0; i < n; ++i) if (ans.r < a[i][k]) ans.r += ans.d; gl(a[0] + (ans.r - a[0][k]) / b[0][k] * b[0]); return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, cnt; int pm[10003], f[10003], g[10003]; long long a[10003], b[10003], c[10003], d[10003]; void ex_gcd(long long, long long, long long &, long long &); int quick_pow(int, int); bool merge(); void fac(int, long long *); void prime(int); long long gcd(long long, long long); int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d", f + i, g + i); prime(f[i]); prime(g[i]); } sort(pm + 1, pm + 1 + cnt); cnt = unique(pm + 1, pm + 1 + cnt) - pm - 1; fac(f[1], a); fac(g[1], b); for (int i = 2; i <= n; ++i) { fac(f[i], c); fac(g[i], d); if (!merge()) return puts("-1"), 0; } int ans = 1; for (int i = 1; i <= cnt; ++i) ans = 1ll * ans * quick_pow(pm[i], a[i] % (mod - 1)) % mod; cout << ans << endl; return 0; } void prime(int x) { for (int i = 2; i * i <= x; ++i) if (x % i == 0) { pm[++cnt] = i; while (x % i == 0) x /= i; } if (x > 1) pm[++cnt] = x; return; } void fac(int x, long long *p) { for (int i = 1; i <= cnt; ++i) { p[i] = 0; while (x % pm[i] == 0) ++p[i], x /= pm[i]; } return; } int quick_pow(int x, int y) { int sum = 1; for (; y; y >>= 1, x = 1ll * x * x % mod) if (y & 1) sum = 1ll * sum * x % mod; return sum; } void ex_gcd(long long x, long long y, long long &a, long long &b) { if (!y) return a = 1, b = 0, void(); ex_gcd(y, x % y, a, b); a -= x / y * b; swap(a, b); return; } long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); } bool merge() { long long cb = 0, cd = 0; for (int i = 1; i <= cnt; ++i) cb += b[i], cd += d[i]; if (!cb && !cd) { for (int i = 1; i <= cnt; ++i) if (a[i] != c[i]) return false; return true; } if (!cb || !cd) { if (!cb) swap(a, c), swap(b, d), swap(cb, cd); long long k = 0; for (int i = 1; i <= cnt; ++i) if (b[i]) { if (c[i] < a[i] || (c[i] - a[i]) % b[i]) return false; k = (c[i] - a[i]) / b[i]; break; } else if (a[i] != c[i]) return false; for (int i = 1; i <= cnt; ++i) { if (a[i] + k * b[i] != c[i]) return false; a[i] += k * b[i]; b[i] = 0; } return true; } int p1 = 0, p2 = 0; for (int i = 1; i <= cnt; ++i) if (b[i] * cd != d[i] * cb) { p1 = i; break; } if (p1) { for (int i = 1; i <= cnt; ++i) if (b[i] * d[p1] != d[i] * b[p1]) { p2 = i; break; } long long x1 = c[p1] * d[p2] - c[p2] * d[p1] - a[p1] * d[p2] + a[p2] * d[p1]; long long x2 = a[p1] * b[p2] - a[p2] * b[p1] - c[p1] * b[p2] + c[p2] * b[p1]; long long y1 = b[p1] * d[p2] - b[p2] * d[p1]; long long y2 = d[p1] * b[p2] - d[p2] * b[p1]; if (x1 * y1 < 0 || x2 * y2 < 0 || abs(x1) % abs(y1) || abs(x2) % abs(y2)) return false; x1 /= y1; x2 /= y2; for (int i = 1; i <= cnt; ++i) { if (a[i] + b[i] * x1 != c[i] + d[i] * x2) return false; a[i] += b[i] * x1; b[i] = 0; } return true; } long long kb, kd, k; for (int i = 1; i <= cnt; ++i) if (b[i]) { long long g = gcd(b[i], d[i]); kb = b[i] / g; kd = d[i] / g; break; } for (int i = 1; i <= cnt; ++i) if (b[i]) { if ((a[i] - c[i]) % (b[i] / kb) == 0) { k = (a[i] - c[i]) / (b[i] / kb); break; } else return false; } for (int i = 1; i <= cnt; ++i) if (c[i] + (b[i] / kb) * k != a[i]) return false; if (k < 0) swap(a, c), swap(b, d), swap(kb, kd), k = -k; long long x, y; ex_gcd(kb, kd, x, y); x = (-k * x % kd + kd) % kd; for (int i = 1; i <= cnt; ++i) a[i] += b[i] * x, b[i] *= kd; return true; }
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long exgcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1, y = 0; return a; } long long g = exgcd(b, a % b, x, y), t = x; x = y, y = t - a / b * y; return g; } long long mypow(long long a, long long n) { long long ans = 1; a %= mod; for (long long i = n; i; i >>= 1, a = a * a % mod) if (i & 1) ans = ans * a % mod; return ans; } const int maxn = 110, maxp = 2010; int p[maxp], pn; int a[maxn][maxp], b[maxn][maxp], n; bool init() { static int u[maxn], v[maxn]; scanf("%d", &n), pn = 0; for (int i = 1, x, y; i <= n; ++i) { scanf("%d%d", u + i, v + i); for (x = u[i], y = 2; y <= x / y; ++y) if (x % y == 0) for (p[++pn] = y; x % y == 0; x /= y) ; if (x != 1) p[++pn] = x; for (x = v[i], y = 2; y <= x / y; ++y) if (x % y == 0) for (p[++pn] = y; x % y == 0; x /= y) ; if (x != 1) p[++pn] = x; } if (n == 1) { printf("%d\n", u[1]); return true; } sort(p + 1, p + pn + 1), pn = unique(p + 1, p + pn + 1) - p - 1; memset(a, 0, sizeof(a)), memset(b, 0, sizeof(b)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= pn; ++j) while (u[i] % p[j] == 0) ++b[i][j], u[i] /= p[j]; for (int j = 1; j <= pn; ++j) while (v[i] % p[j] == 0) ++a[i][j], v[i] /= p[j]; } return false; } struct equation { long long A, B, C; equation() : A(0), B(0), C(0) {} equation(long long newA, long long newB, long long newC) : A(newA), B(newB), C(newC) {} }; bool empty(equation &t) { if (!t.A && !t.B) return t.C; long long g = gcd(abs(t.A), abs(t.B)); if (t.C % g) return true; t.A /= g, t.B /= g, t.C /= g; return false; } int merge(equation p, equation q, long long &x, long long &y) { long long D = p.A * q.B - p.B * q.A; x = p.C * q.B - q.C * p.B, y = p.A * q.C - p.C * q.A; if (D) { if (x % D || y % D) { x = -1, y = -1; return -1; } x /= D, y /= D; return +1; } if (x || y) { x = -1, y = -1; return -1; } return 0; } long long check(long long x) { if (x < 0) return -1; for (int i = 2; i <= n; ++i) { vector<long long> s; s.clear(); for (int u = 1; u <= pn; ++u) { long long z = a[1][u] * x + b[1][u] - b[i][u]; if (a[i][u]) { if (z % a[i][u]) return -1; s.push_back(z / a[i][u]); } else if (z) return -1; } sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); if (s.size() > 1 || (s.size() == 1 && s.front() < 0)) return -1; } long long ans = 1; for (int i = 1; i <= pn; ++i) ans = ans * mypow(p[i], a[1][i] * x + b[1][i]) % mod; return ans; } void solve() { long long x = 0, y = 0; bool find = false; for (int i = 2; !find && i <= n; ++i) for (int u = 1; !find && u <= pn; ++u) { equation p(a[1][u], -a[i][u], b[i][u] - b[1][u]); if (empty(p)) { puts("-1"); return; } if (!p.B && p.A) { x = p.C / p.A, find = true; break; } for (int v = u + 1; v <= pn; ++v) { equation q(a[1][v], -a[i][v], b[i][v] - b[1][v]); int t = merge(p, q, x, y); if (t == +1) { find = true; break; } if (t == -1) { puts("-1"); return; } } } if (find) { printf("%I64d\n", check(x)); return; } static long long c[maxn], d[maxn]; int m = 0; long long minx = 0; for (int i = 2; i <= n; ++i) { for (int u = 1; u <= pn; ++u) if (a[1][u]) { long long A = a[1][u], B = a[i][u], C = b[i][u] - b[1][u]; long long g = exgcd(A, B, x, y); ++m; minx = max(minx, (long long)ceil(1.0 * C / A)); c[m] = (C / g) * x % B, d[m] = B / g; break; } } for (int i = 2; i <= m; ++i) { long long A = d[1], B = d[i], C = c[i] - c[1]; long long g = exgcd(A, B, x, y); if (C % g) { puts("-1"); return; } x = x * (C / g) % B; c[1] = c[1] + x * A, d[1] = A / g * B; c[1] %= d[1]; if (c[1] < 0) c[1] += d[1]; } c[1] += ceil(1.0 * (minx - c[1]) / d[1]); printf("%I64d\n", check(c[1])); } int main() { if (!init()) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; struct pp { int a, b; }; pp pt[111]; int n, fac[211111], num_fac, num, num_row, aa[2111][102], bb[2111][102]; long long now_ex[111]; const int mod = 1e9 + 7; bool vis[111]; long long x, y, d, now_a, now_b, ep[2111]; int ans; void gcd(long long a, long long n) { long long temp; if (n == 0) { d = a; x = 1; y = 0; return; } gcd(n, a % n); temp = x; x = y; y = temp - (a / n) * y; } int power(int a, long long n) { int res; if (n == 0) return 1; res = power(a, n / 2); res = (int)((long long)res * (long long)res % mod); if (n % 2) res = (int)((long long)res * (long long)a % mod); return res; } int main() { int i, j, s, p, q, tmp, a, b, v1, v2; bool add; scanf("%d", &n); num_fac = 0; for (i = 0; i < n; i++) { scanf("%d%d", &pt[i].a, &pt[i].b); for (s = 0; s < 2; s++) { a = pt[i].a; if (s == 1) a = pt[i].b; for (j = 2; j * j <= a; j++) { if (a % j == 0) { fac[num_fac++] = j; while (a % j == 0) a /= j; } } if (a > 1) fac[num_fac++] = a; } } sort(fac, fac + num_fac); num = 0; for (i = 0; i < num_fac; i++) { if (num == 0 || fac[num - 1] != fac[i]) fac[num++] = fac[i]; } num_fac = num; memset(now_ex, -1, sizeof(now_ex)); num_row = 0; memset(aa, 0, sizeof(aa)); memset(bb, 0, sizeof(bb)); for (i = 0; i < num_fac; i++) { for (j = 0; j < n; j++) { a = pt[j].a; while (a % fac[i] == 0) { a /= fac[i]; bb[num_row][j]++; } b = pt[j].b; while (b % fac[i] == 0) { b /= fac[i]; aa[num_row][j]++; } } for (j = 0; j < n; j++) { for (s = 0; s < n; s++) { if (aa[num_row][s] == 0 && aa[num_row][j] != 0) { a = aa[num_row][j]; b = bb[num_row][s] - bb[num_row][j]; if (b % a != 0 || b < 0) { puts("-1"); return 0; } v1 = b / a; if (now_ex[j] >= 0 && now_ex[j] != v1) { puts("-1"); return 0; } if (now_ex[j] < 0) now_ex[j] = v1; } if (aa[num_row][s] == 0 && aa[num_row][j] == 0) { if (bb[num_row][s] != bb[num_row][j]) { puts("-1"); return 0; } } } } if (num_row >= 1) { for (j = 0; j < n; j++) { for (s = 0; s < n; s++) { if (j == s) continue; if (aa[num_row][j] != 0 || aa[num_row][s] != 0) { for (p = num_row - 1; p >= 0; p--) { if (aa[p][j] != 0 || aa[p][s] != 0) break; } if (p < 0) continue; } else { if (bb[num_row][j] != bb[num_row][s]) { puts("-1"); return 0; } continue; } a = aa[num_row][j] * aa[p][s] - aa[p][j] * aa[num_row][s]; b = (bb[num_row][s] - bb[num_row][j]) * aa[p][s] - (bb[p][s] - bb[p][j]) * aa[num_row][s]; if ((a == 0 && b != 0) || (a != 0 && b % a != 0) || (a != 0 && b / a < 0)) { puts("-1"); return 0; } if (a != 0) { v1 = b / a; b = (bb[p][j] - bb[p][s]) * aa[num_row][j] - (bb[num_row][j] - bb[num_row][s]) * aa[p][j]; if (b % a != 0 || b / a < 0) { puts("-1"); return 0; } v2 = b / a; if ((now_ex[j] >= 0 && now_ex[j] != v1) || (now_ex[s] >= 0 && now_ex[s] != v2)) { puts("-1"); return 0; } if (now_ex[j] < 0) now_ex[j] = v1; if (now_ex[s] < 0) now_ex[s] = v2; } } } } num_row++; } if (now_ex[0] < 0) { memset(vis, false, sizeof(vis)); for (j = 0; j < num_fac; j++) { now_a = 1; now_b = 0; for (i = 0; i < n; i++) { if (aa[j][i] == 0) continue; gcd(now_a, aa[j][i]); now_b = bb[j][i] - now_b; if (now_b % d != 0) { puts("-1"); return 0; } x = (long long)x * (long long)(now_b / d) % (aa[j][i] / d); if (x < 0) x += aa[j][i]; now_b = bb[j][i] - now_b; now_b = (x * now_a + now_b) % (now_a * (aa[j][i] / d)); now_a = now_a * (aa[j][i] / d); } for (i = 0; i < n; i++) { while (now_b < bb[j][i]) now_b += now_a; } ep[j] = now_b; } } else { memset(ep, 0, sizeof(ep)); for (j = 0; j < num_fac; j++) { for (i = 0; i < n; i++) { if (now_ex[i] >= 0) { ep[j] = now_ex[i] * aa[j][i] + bb[j][i]; break; } } } } ans = 1; for (i = 0; i < num_fac; i++) ans = (int)((long long)ans * (long long)power(fac[i], ep[i]) % mod); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int N; vector<int> xs, ys; string generateFunc(int i, int x) { char str[1024]; sprintf(str, "(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x / 2, i, i); return string(str); } string solve(vector<int>& xs) { string rv; rv += generateFunc(0, xs[0]); for (int i = 1; i < N; ++i) rv = "(" + rv + "+" + generateFunc(i, xs[i]) + ")"; return rv; } int main() { cin >> N; for (int i = 0; i < N; ++i) { int x, y, r; cin >> x >> y >> r; xs.emplace_back(x); ys.emplace_back(y); } cout << solve(xs) << endl; cout << solve(ys) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int read() { int X = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar(); return X * w; } const int N = 50 + 10; int n, x[N], y[N]; void solve(int* x) { for (int i = 1; i < n; ++i) putchar('('); for (int i = 1; i <= n; ++i) { if (i >= 2) putchar('+'); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[i] >> 1, i, i); if (i >= 2) putchar(')'); } } int main() { n = read(); for (int i = 1; i <= n; ++i) x[i] = read(), y[i] = read(), read(); solve(x), puts(""), solve(y), puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; string singlept(int pt, int val) { ostringstream sstr; sstr << "(((abs((1-abs((t-" << pt << "))))-abs((t-" << pt << ")))+1)*" << val / 2 << ")"; return sstr.str(); } int main() { int n, x, y, r; cin >> n >> x >> y >> r; string retf, rets; for (int i = 1; i < n; i++) { retf += "("; rets += "("; } retf += singlept(0, x); rets += singlept(0, y); for (int i = 1; i < n; i++) { cin >> x >> y >> r; retf += "+" + singlept(i, x) + ")"; rets += "+" + singlept(i, y) + ")"; } cout << retf << '\n' << rets << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, x[105], y[105]; scanf("%d", &n); for (int i = 1, z; i <= n; i++) scanf("%d%d%d", &x[i], &y[i], &z); for (int i = 1; i <= n - 1; i++) printf("("); for (int i = 1; i <= n; i++) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[i] / 2, i - 1, i - 1); if (i != 1) printf(")"); if (i != n) printf("+"); } printf("\n"); for (int i = 1; i <= n - 1; i++) printf("("); for (int i = 1; i <= n; i++) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", y[i] / 2, i - 1, i - 1); if (i != 1) printf(")"); if (i != n) printf("+"); } return 0; }
#include <bits/stdc++.h> using namespace std; string getFunc(int x, int y) { y /= 2; string Y = ""; Y += y % 10 + '0'; string X = ""; X += x % 10 + '0'; if (y >= 10) { Y += y / 10 + '0'; swap(Y[0], Y[1]); } if (x >= 10) { X += x / 10 + '0'; swap(X[0], X[1]); } return "(" + Y + "*((1-abs((t-" + X + ")))+abs((abs((t-" + X + "))-1))))"; } int main() { int n, x, y, r; string ansX, ansY; while (cin >> n) { for (int i = int(0); i < int(n); i++) { cin >> x >> y >> r; if (i) { ansY = '(' + ansY + '+' + getFunc(i, y) + ')'; ansX = '(' + ansX + '+' + getFunc(i, x) + ')'; } else { ansX = getFunc(i, x); ansY = getFunc(i, y); } } cout << ansX << endl; cout << ansY << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string f1, f2; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y, r; cin >> x >> y >> r; if (i) f1 += "+"; if (i) f1 += "(" + to_string(x / 2) + "*(2-abs(((0-abs((t-" + to_string(i - 1) + ")))+abs((t-" + to_string(i + 1) + "))))))"; else f1 += "(" + to_string(x / 2) + "*(2-abs(((0-abs((t+1)))+abs((t-" + to_string(i + 1) + "))))))"; if (i) f2 += "+"; if (i) f2 += "(" + to_string(y / 2) + "*(2-abs(((0-abs((t-" + to_string(i - 1) + ")))+abs((t-" + to_string(i + 1) + "))))))"; else f2 += "(" + to_string(y / 2) + "*(2-abs(((0-abs((t+1)))+abs((t-" + to_string(i + 1) + "))))))"; if (i) { f1 = "(" + f1 + ")"; f2 = "(" + f2 + ")"; } } cout << f1 << endl << f2; }
#include <bits/stdc++.h> using namespace std; inline long long read() { register char ch = getchar(); register long long x = 0; register bool y = 1; while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar(); if (ch == '-') ch = getchar(), y = 0; while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar(); return y ? x : -x; } int point[51][3], n; void solve(int l, int r, int dir) { if (l == r) printf("(%01d*abs(((1-abs((t-%d)))+abs((abs((t-%d))-1)))))", point[l][dir] / 2, l, l); else { printf("("); solve(l, (l + r) >> 1, dir); printf("+"); solve(((l + r) >> 1) + 1, r, dir); printf(")"); } } int main() { n = read(); for (register long long i = 1; i <= n; ++i) point[i][0] = read(), point[i][1] = read(), point[i][2] = read(); solve(1, n, 0); printf("\n"); solve(1, n, 1); return 0; }
#include <bits/stdc++.h> using namespace std; int x[120], y[120], r[120]; char buff[120]; string solve(int a[], int n) { string ans; for (int i = 0; i < n; ++i) if (a[i]) { sprintf(buff, "(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", a[i] / 2, i, i); if (ans.empty()) ans = string(buff); else ans = "(" + ans + "+" + string(buff) + ")"; } if (ans == "") ans = "0"; return ans; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i] >> r[i]; if (x[i] & 1) x[i] ^= 1; if (y[i] & 1) y[i] ^= 1; } cout << solve(x, n) << endl; cout << solve(y, n) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; inline long long read() { long long ret = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar(); return ret * f; } long long n; string f = "", g = ""; string get_string(long long x, long long i) { string ret = "(" + to_string(x) + "*((1-abs((t-" + to_string(i) + ")))+abs((1-abs((t-" + to_string(i) + "))))))"; return ret; } signed main() { n = read(); for (long long i = 1; i <= n; i++) { long long x = read(), y = read(), r = read(); if (i == 1) { f = get_string(x / 2, i); g = get_string(y / 2, i); } else { f = "(" + f + "+" + get_string(x / 2, i) + ")"; g = "(" + g + "+" + get_string(y / 2, i) + ")"; } } cout << f << endl << g << endl; return 0; }
#include <bits/stdc++.h> inline int gi() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } int x[51], y[51]; int main() { int n = gi(); for (int i = 1; i <= n; ++i) x[i] = gi(), y[i] = gi(), gi(); for (int i = 1; i < n; ++i) putchar('('); for (int i = 1; i <= n; ++i) { printf("(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", x[i] / 2, i, i); if (i != 1) printf(")"); printf("%c", "+\n"[i == n]); } for (int i = 1; i < n; ++i) putchar('('); for (int i = 1; i <= n; ++i) { printf("(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", y[i] / 2, i, i); if (i != 1) printf(")"); printf("%c", "+\n"[i == n]); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 55; pair<int, int> a[N]; int main() { int n; scanf("%d", &n); int r; for (int i = 0; i < n; ++i) { scanf("%d%d%d", &a[i].first, &a[i].second, &r); } string left = "(((1-abs((t-", mid = ")))+abs((abs((t-", right = "))-1)))"; string ans1 = ""; string ans2 = ""; for (int i = 0; i < n - 1; ++i) { ans1 += "("; ans2 += "("; } for (int i = 0; i < n; ++i) { string num = to_string(i); ans1 += left + num + mid + num + right + "*" + to_string(a[i].first / 2) + ")"; ans2 += left + num + mid + num + right + "*" + to_string(a[i].second / 2) + ")"; if (i != 0) ans1 += ")", ans2 += ")"; if (i != n - 1) ans1 += "+", ans2 += "+"; } cout << ans1 << endl; cout << ans2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline void Min(T &a, T b) { if (a > b) a = b; } template <class T> inline void Max(T &a, T b) { if (a < b) a = b; } string s, ans, res; void cal(string &s, int first, int i) { s.clear(); int n = 0; s += "("; first /= 2; char b[10]; int m = 0; while (first > 0) b[m++] = first % 10 + '0', first /= 10; if (m == 0) b[m++] = '0'; for (int i = m - 1; i >= 0; i--) s += b[i]; s += "*"; string t = "t-"; first = i; m = 0; while (first > 0) b[m++] = first % 10 + '0', first /= 10; if (m == 0) b[m++] = '0'; for (int i = m - 1; i >= 0; i--) t += b[i]; t = "abs((" + t + "))"; s += "((1-" + t + ")+abs((" + t + "-1))))"; } int main() { int T, i, j, k, n, m; scanf("%d", &n); for (i = 0; i < n; i++) { int first, second; scanf("%d%d%d", &first, &second, &k); cal(s, first, i); if (i) ans = "(" + ans + "+" + s + ")"; else ans = s; cal(s, second, i); if (i) res = "(" + res + "+" + s + ")"; else res = s; } cout << ans << "\n" << res << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int x[100100], y[100100]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { int r; scanf("%d%d%d", &x[i], &y[i], &r); x[i] /= 2; y[i] /= 2; } for (int i = 1; i < n; i++) printf("("); for (int i = 1; i <= n; i++) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[i], i, i); if (i > 1) printf(")"); if (i < n) printf("+"); } puts(""); for (int i = 1; i < n; i++) printf("("); for (int i = 1; i <= n; i++) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", y[i], i, i); if (i > 1) printf(")"); if (i < n) printf("+"); } return 0; }
#include <bits/stdc++.h> using namespace std; int n, x[55], y[55], r[55]; string s[55], ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d%d%d", &x[i], &y[i], &r[i]); for (int i = 1; i <= n; ++i) { s[i] = ""; x[i] /= 2; if (x[i] < 10) s[i] += '0' + x[i]; else { s[i] += ('0' + x[i] / 10); s[i] += ('0' + x[i] % 10); } s[i] += '*'; s[i] += '('; s[i] += '('; s[i] += '1'; s[i] += '-'; s[i] += "abs("; s[i] += "(t-"; if (i < 10) s[i] += '0' + i; else { s[i] += ('0' + i / 10); s[i] += ('0' + i % 10); } s[i] += ")))+abs((1-abs((t-"; if (i < 10) s[i] += '0' + i; else { s[i] += ('0' + i / 10); s[i] += ('0' + i % 10); } s[i] += ")))))"; s[i] = '(' + s[i] + ')'; } ans = s[1]; for (int i = 2; i <= n; ++i) { ans = '(' + ans + '+' + s[i] + ')'; } cout << ans << endl; for (int i = 1; i <= n; ++i) x[i] = y[i]; for (int i = 1; i <= n; ++i) { s[i] = ""; x[i] /= 2; if (x[i] < 10) s[i] += '0' + x[i]; else { s[i] += ('0' + x[i] / 10); s[i] += ('0' + x[i] % 10); } s[i] += '*'; s[i] += '('; s[i] += '('; s[i] += '1'; s[i] += '-'; s[i] += "abs("; s[i] += "(t-"; if (i < 10) s[i] += '0' + i; else { s[i] += ('0' + i / 10); s[i] += ('0' + i % 10); } s[i] += ")))+abs((1-abs((t-"; if (i < 10) s[i] += '0' + i; else { s[i] += ('0' + i / 10); s[i] += ('0' + i % 10); } s[i] += ")))))"; s[i] = '(' + s[i] + ')'; } ans = s[1]; for (int i = 2; i <= n; ++i) { ans = '(' + ans + '+' + s[i] + ')'; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; inline int ty() { register int a = 0, b = 1, c = getchar(); while (!isdigit(c)) b ^= c == '-', c = getchar(); while (isdigit(c)) a = a * 10 + c - 48, c = getchar(); return b ? a : -a; } const int _ = 53; struct node { int x, y; node(int _x = 0, int _y = 0) { x = _x, y = _y; } inline friend int operator<(node a, node b) { return a.x < b.x; } } p[_]; int n; const string st = "(((1-abs((t-", md = ")))+abs((1-abs((t-", en = ")))))*"; int main() { register int i, a, b; n = ty(); for (i = 1; i <= n; i++) a = ty(), b = ty(), ty(), p[i] = node(a, b); sort(p + 1, p + n + 1); register string F = "", G = "", x; for (i = 1; i < n; i++) F += '(', G += '('; for (i = 1; i <= n; i++) { x = to_string(i - 1); F += st + x + md + x + en + to_string(p[i].x / 2) + ")"; G += st + x + md + x + en + to_string(p[i].y / 2) + ")"; if (i > 1) F += ')', G += ')'; if (i < n) F += '+', G += '+'; } cout << F << endl << G << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; int x[50], y[50], r[50]; int f(int t) { return ( ((0 + (((abs((t - 0)) + t) - 0) * 0)) + (((abs((t - 1)) + t) - 1) * 5)) + (((abs((t - 2)) + t) - 2) * 0)); } int g(int t) { return (((0 + (((abs((t - 0)) + t) - 0) * 5)) + (((abs((t - 1)) + t) - 1) * (0 - 10))) + (((abs((t - 2)) + t) - 2) * 10)); } string i2s(int x) { char tmp[10]; sprintf(tmp, "%d", x); return tmp; } int d[100]; string solve(int *a) { string res = "0"; int prev = 0; for (int i = 0; i < n; i++) { int prev = 0; for (int j = 0; j < i; j++) { prev += (i - j + 1) * 2 * d[j]; } int dist = a[i] - prev; string offset = ""; if (dist >= 0) { dist /= 2; offset = i2s(dist); d[i] = dist; } else { dist = -dist; dist /= 2; offset = "(0-" + i2s(dist) + ")"; d[i] = -dist; } string step = "((abs((t-" + i2s(i) + "))+t)-" + i2s(i) + ")"; string jump = "(" + step + "*" + offset + ")"; res = "(" + res + "+" + jump + ")"; } return res; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i]; cout << solve(x) << endl << solve(y) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; int n; int c[MAXN][3]; void load() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) cin >> c[i][0] >> c[i][1] >> c[i][2]; } void create(int x, int i, string &s) { char buff[50]; sprintf(buff, "(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", x / 2, i, i); s = string(buff, strlen(buff)); } void solve() { string x = "", y = ""; for (int i = 0; i < n; ++i) { string w; create(c[i][0], i + 1, w); if (x.length()) x = "(" + x + "+" + w + ")"; else x = w; create(c[i][1], i + 1, w); if (y.length()) y = "(" + y + "+" + w + ")"; else y = w; } cout << x << endl; cout << y << endl; } int main() { load(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxN = 59; struct vt { int x, y, r; vt() : x(0), y(0), r(0) {} vt(int x, int y, int r) { this->x = x; this->y = y; this->r = r; } }; vector<vt> point(maxN); string s1, s2; pair<int, int> rec(int x, int y, int l, int r) { if (l + 1 == r) { int ll = l; int next_x = point[l + 1].x, next_y = point[l + 1].y; if (abs(next_x - x) % 2 == 1) --next_x; if (abs(next_y - y) % 2 == 1) --next_y; int e_x = (next_x - x) / 2, e_y = (next_y - y) / 2; s1 += "("; s2 += "("; bool q = false, w = false; if (e_x < 0) { e_x = -e_x; q = true; } if (e_y < 0) { e_y = -e_y; w = true; } if (q) s1 += "(0-"; if (e_x / 10 > 0) { s1 += (char)(e_x / 10 + '0'); } s1 += (char)(e_x % 10 + '0'); if (q) s1 += ")"; if (w) s2 += "(0-"; if (e_y / 10 > 0) { s2 += (char)(e_y / 10 + '0'); } s2 += (char)(e_y % 10 + '0'); if (w) s2 += ")"; s1 += "*(1+(abs((t-"; s2 += "*(1+(abs((t-"; bool k = false; if (ll < 0) { k = true; ll = -ll; s1 += "(0-"; s2 += "(0-"; } if (ll / 10 > 0) { s1 += (char)(ll / 10 + '0'); s2 += (char)(ll / 10 + '0'); } s1 += (char)(ll % 10 + '0'); s2 += (char)(ll % 10 + '0'); if (k) { s1 += ")"; s2 += ")"; } s1 += "))-abs((t-"; s2 += "))-abs((t-"; ll = r; if (ll / 10 > 0) { s1 += (char)(ll / 10 + '0'); s2 += (char)(ll / 10 + '0'); } s1 += (char)(ll % 10 + '0'); s2 += (char)(ll % 10 + '0'); s1 += ")))))"; s2 += ")))))"; return make_pair(next_x, next_y); } else { int m = (l + r) / 2; s1 += '('; s2 += '('; pair<int, int> t = rec(x, y, l, m); s1 += '+'; s2 += '+'; t = rec(t.first, t.second, m, r); s1 += ')'; s2 += ')'; return t; } } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> point[i].x >> point[i].y >> point[i].r; } pair<int, int> t = rec(0, 0, -1, n - 1); cout << s1 << endl; cout << s2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; inline int read() { int a = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) { a = (a << 3) + (a << 1) + (c ^ '0'); c = getchar(); } return f ? -a : a; } int point[51][3], N; void solve(int l, int r, int dir) { if (l == r) printf("(%01d*abs(((1-abs((t-%d)))+abs((abs((t-%d))-1)))))", point[l][dir] / 2, l, l); else { putchar('('); solve(l, l + r >> 1, dir); putchar('+'); solve((l + r >> 1) + 1, r, dir); putchar(')'); } } int main() { N = read(); for (int i = 1; i <= N; ++i) { point[i][0] = read(); point[i][1] = read(); point[i][2] = read(); } solve(1, N, 0); putchar('\n'); solve(1, N, 1); return 0; }
#include <bits/stdc++.h> int n, x[2][105]; void solve(int id) { for (int i = 1; i < n; i++) printf("("); for (int i = 1; i <= n; i++) { if (i != 1) printf("+"); printf("(%d*(abs((abs((t-%d))-1))-(abs((t-%d))-1)))", x[id][i] / 2, i, i); if (i != 1) printf(")"); } puts(""); } int main() { int m, i, k, j, z; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d%d%d", &x[0][i], &x[1][i], &z); solve(0); solve(1); return 0; }
#include <bits/stdc++.h> using namespace std; int n; string make(int i, int a) { char st[10]; sprintf(st, "%d", i); string num = string(st); string ret = "((1-abs((t-" + num + ")))+abs((1-abs((t-" + num + ")))))"; sprintf(st, "%d", a / 2); num = string(st); return "(" + num + "*" + ret + ")"; } int main() { scanf("%d", &n); string f = string("0"); string g = string("0"); for (int i = 0; i < n; i++) { int x, y, r; scanf("%d%d%d", &x, &y, &r); f = "(" + f + "+" + make(i, x) + ")"; g = "(" + g + "+" + make(i, y) + ")"; } cout << f << endl; cout << g << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3; int x[MAXN], y[MAXN], r[MAXN]; string intTo(int k) { if (k == 0) return "0"; string s = ""; while (k > 0) s += '0' + k % 10, k /= 10; reverse((s).begin(), (s).end()); return s; } int main() { int n; scanf("%d", &n); for (int i = 0; (i) < (n); ++i) scanf("%d%d%d", &x[i], &y[i], &r[i]); string f = "0", g = "0"; for (int i = 0; (i) < (n); ++i) { string t = intTo(i); f = "(" + f + "+(" + intTo(x[i] / 2) + "*" + "(abs((abs((t-" + t + "))-1))-(abs((t-" + t + "))-1))" + "))"; g = "(" + g + "+(" + intTo(y[i] / 2) + "*" + "(abs((abs((t-" + t + "))-1))-(abs((t-" + t + "))-1))" + "))"; } cout << f << endl; cout << g << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string ans1, ans2; stringstream t1, t2; scanf("%d", &n); ans1 = ans2 = "0"; int xx = 0, yy = 0, dx, dy; for (int i = 0; i < n; i++) { int x, y, r; cin >> x >> y >> r; if (x & 1) x--; if (y & 1) y--; dx = x - xx; dy = y - yy; t1.str(""); t2.str(""); t1 << (dx >= 0 ? '+' : '-') << "(" << abs(dx / 2) << "*((abs((t-" << i << "))-abs((t-" << i + 1 << ")))+1))"; t2 << (dy >= 0 ? '+' : '-') << "(" << abs(dy / 2) << "*((abs((t-" << i << "))-abs((t-" << i + 1 << ")))+1))"; ans1 = "(" + ans1 + t1.str() + ")"; ans2 = "(" + ans2 + t2.str() + ")"; xx = x; yy = y; } cout << ans1 << endl; cout << ans2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int x[55], y[55]; void print(int* x, int n) { for (int i = 1; i < n; i++) putchar('('); for (int i = 1; i <= n; i++) { if (i != 1) putchar('+'); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[i] / 2, i, i); if (i != 1) putchar(')'); } puts(""); } int main(void) { int n, k; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d %d %d", x + i, y + i, &k); print(x, n), print(y, n); return 0; }
#include <bits/stdc++.h> inline int gi() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } int x[51], y[51]; int main() { int n = gi(); for (int i = 1; i <= n; ++i) x[i] = gi(), y[i] = gi(), gi(); for (int i = 1; i < n; ++i) putchar('('); for (int i = 1; i <= n; ++i) { printf("(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", x[i] / 2, i, i); if (i != 1) printf(")"); printf("%c", "+\n"[i == n]); } for (int i = 1; i < n; ++i) putchar('('); for (int i = 1; i <= n; ++i) { printf("(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", y[i] / 2, i, i); if (i != 1) printf(")"); printf("%c", "+\n"[i == n]); } return 0; }
#include <bits/stdc++.h> using namespace std; int x[55], y[55]; int n; int main() { int i, j; scanf("%d", &n); for (i = 1; i <= n; ++i) scanf("%d%d%*d", x + i, y + i); for (i = 1; i < n; ++i) putchar('('); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[1] >> 1, 0, 0); for (i = 2; i <= n; ++i) { putchar('+'); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1)))))", x[i] >> 1, i, i); } putchar('\n'); for (i = 1; i < n; ++i) putchar('('); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", y[1] >> 1, 0, 0); for (i = 2; i <= n; ++i) { putchar('+'); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1)))))", y[i] >> 1, i, i); } putchar('\n'); return 0; }
#include <bits/stdc++.h> using namespace std; void solve(vector<int> v) { int n = v.size(); int x = v[0], y = v.back(); v.insert(v.begin(), x); v.push_back(y); int D = (x + y) / 2; string s = to_string(D); assert(D >= 0 && D <= 50); for (int i = 1; i <= n; i++) { int d = (v[i + 1] + v[i - 1]) / 2 - v[i]; assert(abs(d) <= 50); string aa = "abs((t-" + to_string(i - 1) + "))"; string bb = "(" + to_string(abs(d)) + "*" + aa + ")"; if (d > 0) { s = "(" + s + "+" + bb + ")"; } else { s = "(" + s + "-" + bb + ")"; } } cout << s << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> v1, v2; for (int i = 0; i < n; i++) { int x, y, r; cin >> x >> y >> r; if (x % 2) x++; if (y % 2) y++; v1.push_back(x); v2.push_back(y); } solve(v1); solve(v2); }
#include <bits/stdc++.h> using namespace std; int n, a[10000], b[10000], c[10000]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &a[i], &b[i], &c[i]); } for (int i = 1; i < n; i++) printf("("); for (int i = 1; i <= n; i++) { if (i > 1) printf("+"); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", a[i] / 2, i - 1, i - 1); if (i > 1) printf(")"); } printf("\n"); for (int i = 1; i < n; i++) printf("("); for (int i = 1; i <= n; i++) { if (i > 1) printf("+"); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", b[i] / 2, i - 1, i - 1); if (i > 1) printf(")"); } printf("\n"); }
#include <bits/stdc++.h> using namespace std; string generateOne(int k, int A) { int B = A / 2; char temp[1000]; sprintf(temp, "((1-abs((t-%d)))+abs((1-abs((t-%d)))))", k, k); string s(temp); sprintf(temp, "(%d*%s)", B, s.c_str()); string res(temp); return res; } string generate(int n, const vector<int>& vals) { string res = ""; for (int i = 0; i < n; i++) { string ff = generateOne(i, vals[i]); if (i == 0) res = ff; else res = "(" + res + "+" + ff + ")"; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> x(n), y(n), r(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i]; string f = generate(n, x); string g = generate(n, y); cout << f << "\n"; cout << g << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 55; int n; int ar[2][N]; void work(int ttt) { const int *a = ar[ttt]; for (int i = 0; i < n - 1; i++) putchar('('); for (int now = 0; now < n; now++) { printf("((2-abs((abs((t-(%d-1)))-abs((t-(%d+1))))))*%d)", now, 1 * now, a[now] / 2); if (now) putchar(')'); if (now < n - 1) putchar('+'); } putchar(10); } int main() { scanf("%d", &n); int r; for (int i = 0; i < n; i++) scanf("%d%d%d", &ar[0][i], &ar[1][i], &r); work(0); work(1); return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int dr[8] = {1, 1, 0, -1, -1, -1, 0, 1}; int dc[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int dh[4] = {0, 1, 0, -1}; int dv[4] = {-1, 0, 1, 0}; int n; void gen(vector<int> v) { int i; for (i = 0; i < n - 1; i++) cout << "("; for (i = 0; i < n; i++) { cout << "("; cout << v[i] / 2; cout << "*((1-abs((t-" << i << ")))+abs((abs((t-" << i << "))-1))))"; if (i > 0) cout << ")"; if (i < n - 1) cout << "+"; } cout << endl; } int main() { cin >> n; int i, a, b, r; vector<int> X, Y; for (i = 0; i < n; i++) { cin >> a >> b >> r; X.push_back(a); Y.push_back(b); } gen(X); gen(Y); return 0; }
#include <bits/stdc++.h> using namespace std; string generateOne(int i, int x) { int b = x / 2; char temp[100]; sprintf(temp, "((1-abs((t-%d)))+abs((abs((t-%d))-1)))", i, i); string s(temp); sprintf(temp, "(%d*%s)", b, s.c_str()); string res(temp); return res; } string generate(int n, const vector<int> &vals) { string res = ""; for (int i = 0; i < n; i++) { string ff = generateOne(i, vals[i]); if (i == 0) res = ff; else { res = "(" + res + "+" + ff + ")"; } } return res; } int main() { int n, r; scanf("%d", &n); vector<int> x(n), y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> r; } string f = generate(n, x); string g = generate(n, y); cout << f << endl << g << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string itos(long long n) { ostringstream o; o << n; return o.str(); } void run() { int n; cin >> n; vector<pair<long long, long long> > c(n); long long r; for (int i = 0; i < n; i++) cin >> c[i].first >> c[i].second >> r; string x = ""; string y = ""; for (int i = 0; i < n; i++) { string a = "1"; string b = "abs((t-" + itos(i) + "))"; string base = "(" + a + "-" + b + ")+abs((" + b + "-" + a + "))"; string x1 = "(" + itos(c[i].first / 2) + "*(" + base + "))"; string y1 = "(" + itos(c[i].second / 2) + "*(" + base + "))"; if (i == 0) { x = x1; y = y1; } else { x = "(" + x + "+" + x1 + ")"; y = "(" + y + "+" + y1 + ")"; } } cout << x << "\n"; cout << y << "\n"; } int main() { cout << fixed << setprecision(16); run(); return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const double eps = 1e-10; int read() { char ch = getchar(); int data = 0; while (ch < '0' || ch > '9') ch = getchar(); do { data = data * 10 + ch - '0'; ch = getchar(); } while (ch >= '0' && ch <= '9'); return data; } int main() { int x[100], y[100], i, j, k, n, m; cin >> n; for (i = 1; i <= n; i++) cin >> x[i] >> y[i] >> m; for (i = 1; i < n; i++) { if (i == 1) for (j = 1; j < n; j++) cout << "("; if (i == 1) cout << "(" << x[i] / 2 << "*((1-abs((" << i << "-t)))+abs((abs((" << i << "-t))-1))))+"; else cout << "(" << x[i] / 2 << "*((1-abs((" << i << "-t)))+abs((abs((" << i << "-t))-1)))))+"; } if (n > 1) cout << "(" << x[n] / 2 << "*((1-abs((" << n << "-t)))+abs((abs((" << n << "-t))-1)))))" << endl; else cout << "(" << x[n] / 2 << "*((1-abs((" << n << "-t)))+abs((abs((" << n << "-t))-1))))" << endl; for (i = 1; i < n; i++) { if (i == 1) for (j = 1; j < n; j++) cout << "("; if (i == 1) cout << "(" << y[i] / 2 << "*((1-abs((" << i << "-t)))+abs((abs((" << i << "-t))-1))))+"; else cout << "(" << y[i] / 2 << "*((1-abs((" << i << "-t)))+abs((abs((" << i << "-t))-1)))))+"; } if (n > 1) cout << "(" << y[n] / 2 << "*((1-abs((" << n << "-t)))+abs((abs((" << n << "-t))-1)))))" << endl; else cout << "(" << y[n] / 2 << "*((1-abs((" << n << "-t)))+abs((abs((" << n << "-t))-1))))" << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 55; int x[N], y[N]; int main() { int n, z; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d%d%d", &x[i], &y[i], &z); for (int i = 1; i <= n - 1; ++i) printf("("); for (int i = 1; i <= n; ++i) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[i] / 2, i, i); if (i > 1) printf(")"); if (i < n) printf("+"); } puts(""); for (int i = 1; i <= n - 1; ++i) printf("("); for (int i = 1; i <= n; ++i) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", y[i] / 2, i, i); if (i > 1) printf(")"); if (i < n) printf("+"); } return 0; }
#include <bits/stdc++.h> using namespace std; int N, x[60], y[60], r; int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) { scanf("%d%d%d", &x[i], &y[i], &r); x[i] /= 2; y[i] /= 2; } for (int i = 1; i < N; ++i) cout << "("; for (int i = 1; i <= N; ++i) { if (i > 1) { cout << "+"; } cout << "(" << x[i] << "*((1-abs((t-" << i - 1 << ")))+abs((abs((t-" << i - 1 << "))-1))))"; if (i > 1) cout << ")"; } cout << "\n"; for (int i = 1; i < N; ++i) cout << "("; for (int i = 1; i <= N; ++i) { if (i > 1) { cout << "+"; } cout << "(" << y[i] << "*((1-abs((t-" << i - 1 << ")))+abs((abs((t-" << i - 1 << "))-1))))"; if (i > 1) cout << ")"; } cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int n, i, j; int x, y, r; int F1[50], F2[50]; int printN(int a) { if (a < 0) { cout << "(0-"; printN(-a); cout << ")"; } else if (a <= 50) cout << a; else { cout << "(50+"; printN(a - 50); cout << ")"; } return 0; } int printF(int *F, int i) { int m = F[i], a = F[i - 1], b = F[i + 1]; cout << "(("; printN(m); cout << "+("; printN((b - a) / 2); cout << "*((t-" << i << ")-abs((t-" << i << ")))))+abs("; for (int j = i; j < n; j++) F[j] -= m; if (i < n - 2) printF(F, i + 1); else { cout << "("; printN(b - m); cout << "*(t-" << i << "))"; } cout << "))"; return 0; } int main() { cin >> n; for (i = 0; i < n; i++) { cin >> x >> y >> r; F1[i] = 2 * (x / 2); F2[i] = 2 * (y / 2); } if (n == 1) cout << F1[0] << endl << F2[0]; else if (n == 2) { cout << "(" << F1[0]; if (F1[1] >= F1[0]) cout << "+(" << F1[1] - F1[0]; else cout << "-(" << F1[0] - F1[1]; cout << "*t))" << endl; cout << "(" << F2[0]; if (F2[1] > F2[0]) cout << "+(" << F2[1] - F2[0]; else cout << "-(" << F2[0] - F2[1]; cout << "*t))"; } else { for (i = 0; i < n; i++) F1[i] += i * 50, F2[i] += i * 50; cout << "("; printF(F1, 1); cout << "-(50*t))" << endl; cout << "("; printF(F2, 1); cout << "-(50*t))"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> x(n), y(n); for (int i = 0; i < n; ++i) { int foo; cin >> x[i] >> y[i] >> foo; x[i] /= 2; y[i] /= 2; } function<void(int, vector<int>)> solve = [&](int cur, const vector<int>& a) { if (cur == (int)a.size()) { return; } if (cur) { cout << '+'; } cout << "("; cout << a[cur] << "*("; cout << "(1-abs((t-"; cout << cur << ")))+abs(("; cout << "abs((t-"; cout << cur << "))-1))))"; if (cur) { cout << ')'; } solve(cur + 1, a); }; cout << string(n - 1, '('); solve(0, x); cout << '\n'; cout << string(n - 1, '('); solve(0, y); }
#include <bits/stdc++.h> template <class T> void print_arr(T* arr, int n) { for (int i = 0; i < n; ++i) std::cout << arr[i] << ' '; std::cout << std::endl; } const double EPS = 1e-6; using namespace std; void process(int caseNum) {} int main() { int n; cin >> n; if (n == 1) { int x, y; cin >> x >> y; cout << x << endl << y << endl; } else { int xarr[57], yarr[57]; int r; for (int i = 0; i < (n); ++i) cin >> xarr[i] >> yarr[i] >> r; cout << string(n - 1, '('); printf("(%d*((1-t)+abs((1-t))))", xarr[0] / 2); for (int i = 1; i < n; ++i) { printf( "+(((((%d-t)+abs((%d-t)))-((%d-t)+abs((%d-t))))-(((%d-t)+abs((%d-t)))" "-((%d-t)+abs((%d-t)))))*%d))", i + 1, i + 1, i, i, i, i, i - 1, i - 1, xarr[i] / 2); } cout << endl; cout << string(n - 1, '('); printf("(%d*((1-t)+abs((1-t))))", yarr[0] / 2); for (int i = 1; i < n; ++i) { printf( "+(((((%d-t)+abs((%d-t)))-((%d-t)+abs((%d-t))))-(((%d-t)+abs((%d-t)))" "-((%d-t)+abs((%d-t)))))*%d))", i + 1, i + 1, i, i, i, i, i - 1, i - 1, yarr[i] / 2); } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string getone(int x, int i) { x /= 2; char tmp[10005]; sprintf(tmp, "(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x, i, i); string res(tmp); return res; } string getans(int n, int *X) { string ans = ""; for (int i = 1; i <= n; ++i) { if (i == 1) ans = getone(X[i], i - 1); else ans = '(' + ans + '+' + getone(X[i], i - 1) + ')'; } return ans; } int main() { int n; int X[55], Y[55], r; cin >> n; for (int i = 1; i <= n; ++i) { cin >> X[i] >> Y[i] >> r; } cout << getans(n, X) << endl << getans(n, Y) << endl; }
#include <bits/stdc++.h> using namespace std; int n, x[55], y[55], s[55]; void f() { for (int i = (1); i <= (n - 1); i++) printf("("); for (int i = (1); i <= (n); i++) { if (i < 50) printf("(%d*((abs((t-%d))+abs((t-%d)))-(abs((t-%d))+abs((t-%d)))))", s[i], i + 1, i - 1, i, i); else printf("(%d*((abs((t-%d))+abs((t-(50+1))))-(abs((t-%d))+abs((t-%d)))))", s[i], i - 1, i, i); if (i > 1) printf(")"); if (i < n) printf("+"); else printf("\n"); } return; } int main() { scanf("%d", &n); for (int i = (1); i <= (n); i++) { int k; scanf("%d %d %d", &x[i], &y[i], &k); if (x[i] & 1) { if (x[i] > 0) x[i]--; else x[i]++; } if (y[i] & 1) { if (y[i] > 0) y[i]--; else y[i]++; } } for (int i = (1); i <= (n); i++) s[i] = x[i] / 2; f(); for (int i = (1); i <= (n); i++) s[i] = y[i] / 2; f(); return 0; }
#include <bits/stdc++.h> using namespace std; string singleFunction(int c, int t_0) { string ret = "("; if (c < 0) ret += "(0-" + to_string(abs(c)) + ")"; else ret += to_string(abs(c)); ret += "*((t-" + to_string(t_0) + ")+abs((t-" + to_string(t_0) + "))))"; return ret; } string makeFunction(int* x, int n) { int* dx = new int[n]; int* c = new int[n]; dx[0] = x[0]; for (int i = 1; i < n; i++) dx[i] = x[i] - x[i - 1]; c[0] = dx[0] / 2; for (int i = 1; i < n; i++) c[i] = (dx[i] - dx[i - 1]) / 2; string ret = ""; for (int i = 0; i < n; i++) { if (i != n - 1) ret += "("; ret += singleFunction(c[i], i); if (i != n - 1) { ret += "+"; } } for (int i = 0; i < n - 1; i++) ret += ")"; return ret; } int main(void) { int n; cin >> n; int* x = new int[n]; int* y = new int[n]; int r; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> r; if (x[i] % 2 == 1) x[i]++; if (y[i] % 2 == 1) y[i]++; } cout << makeFunction(x, n) << endl; cout << makeFunction(y, n) << endl; }
#include <bits/stdc++.h> using namespace std; int n; int x[50], y[50], r[50]; int f(int t) { return ( ((0 + (((abs((t - 0)) + t) - 0) * 0)) + (((abs((t - 1)) + t) - 1) * 5)) + (((abs((t - 2)) + t) - 2) * 0)); } int g(int t) { return (((0 + (((abs((t - 0)) + t) - 0) * 5)) + (((abs((t - 1)) + t) - 1) * (0 - 10))) + (((abs((t - 2)) + t) - 2) * 10)); } string i2s(int x) { char tmp[10]; sprintf(tmp, "%d", x); return tmp; } int d[100]; string solve(int *a) { string res = "0"; int prev = 0; for (int i = 0; i < n; i++) { int prev = 0; for (int j = 0; j < i; j++) { prev += (i - j + 1) * 2 * d[j]; } int dist = a[i] - prev; string offset = ""; if (dist >= 0) { dist /= 2; offset = i2s(dist); d[i] = dist; } else { dist = -dist; dist /= 2; offset = "(0-" + i2s(dist) + ")"; d[i] = -dist; } string step = "((abs((t-" + i2s(i) + "))+t)-" + i2s(i) + ")"; string jump = "(" + step + "*" + offset + ")"; res = "(" + res + "+" + jump + ")"; } return res; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i]; cout << solve(x) << endl << solve(y) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; int x, y, r; string f, g; string trans(int q); int main() { ios_base::sync_with_stdio(false); cin >> n; f = ""; g = ""; for (int i = 0; i < n; ++i) { cin >> x >> y >> r; x /= 2; y /= 2; string a = ""; string b = ""; a += "(((1-abs((t-"; a += trans(i); a += ")))+abs((abs((t-"; a += trans(i); a += "))-1)))*"; a += trans(x); a += ")"; b += "(((1-abs((t-"; b += trans(i); b += ")))+abs((abs((t-"; b += trans(i); b += "))-1)))*"; b += trans(y); b += ")"; if (f.length() == 0) f += a; else { f = "(" + f; f += "+"; f += a; f += ")"; } if (g.length() == 0) g += b; else { g = "(" + g; g += "+"; g += b; g += ")"; } } cout << f << endl; cout << g << endl; return 0; } string trans(int q) { string e = ""; if (q == 0) e += "0"; else { while (q > 0) { int p = q % 10; char c = char('0' + p); e = c + e; q /= 10; } } return e; }
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; string in(int a) { string s; if (a == 0) return "+0"; int b = a; a = abs(a); while (a > 0) { s = (char)(a % 10 + '0') + s; a /= 10; } if (b > 0) s = "-" + s; else s = "+" + s; return s; } string in1(int a) { string s; if (a == 0) return "0"; a = abs(a); while (a > 0) { s = (char)(a % 10 + '0') + s; a /= 10; } return s; } string get(int a, int b) { string s = "((abs((t" + in(a + 1) + "))+abs((t" + in(a - 1) + ")))-(abs((t" + in(a) + "))+abs((t" + in(a) + "))))"; s = "(" + in1(b) + "*" + s + ")"; return s; } void solve(int n) { int i, j, m, t, a, b; vector<int> v[70]; for (i = 0; i < n; i++) v[i].resize(3); for (i = 0; i < n; i++) { scanf("%d%d%d", &a, &b, &t); v[i][0] = i; v[i][1] = (a + a % 2) / 2; v[i][2] = (b + b % 2) / 2; } string s = get(v[0][0], v[0][1]); for (i = 1; i < n; i++) { s = "(" + s + "+" + get(v[i][0], v[i][1]) + ")"; } printf("%s\n", s.c_str()); s = get(v[0][0], v[0][2]); for (i = 1; i < n; i++) { s = "(" + s + "+" + get(v[i][0], v[i][2]) + ")"; } printf("%s\n", s.c_str()); } int main() { #pragma comment(linker, "/STACK:1073741824") int n, m, k, i; scanf("%d", &n); solve(n); return 0; }
#include <bits/stdc++.h> using namespace std; int n; int x[51]; int y[51]; int r[51]; string __to_string(int x) { string res; while (x > 0) { res += char(x % 10 + 48); x /= 10; } reverse(res.begin(), res.end()); if (res.empty()) res = "0"; return res; } void solve(int *x) { int now = x[1]; int cnt[51]; int c = x[1]; for (int i = 0; i <= n; i++) cnt[i] = 0; string ans; for (int i = 1; i <= n; i++) { string t = "abs((t-" + __to_string(i) + "))"; string c = __to_string(x[i] / 2); if (ans.empty()) ans = "(" + __to_string(x[i] / 2) + "*((1-" + t + ")+abs((" + t + "-1))))"; else ans = "(" + ans + "+(" + __to_string(x[i] / 2) + "*((1-" + t + ")+abs((" + t + "-1)))))"; } cout << ans << '\n'; ; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> r[i]; solve(x); solve(y); }
#include <bits/stdc++.h> using namespace std; string l = "(((1-abs((t-", mid = ")))+abs((abs((t-", r = "))-1)))*"; string an1 = "", an2 = ""; int n; string str(int x) { int A[55], l = 0; do { A[++l] = x % 10; x /= 10; } while (x); string res = ""; for (int i = l; i >= 1; i--) res += (A[i] ^ '0'); return res; } int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { an1 += '('; an2 += '('; } for (int i = 0, x, y, a; i < n; i++) { scanf("%d %d %d", &x, &y, &a); an1 += l + str(i) + mid + str(i) + r + str(x / 2) + ')'; an2 += l + str(i) + mid + str(i) + r + str(y / 2) + ')'; if (i != 0) an1 += ')', an2 += ')'; if (i != n - 1) an1 += '+', an2 += '+'; } cout << an1 << endl; cout << an2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int x[55], y[55]; int main() { int n, t; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%d", &x[i], &y[i], &t); for (int i = 1; i < n; i++) putchar('('); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[1] / 2, 1, 1); for (int i = 2; i <= n; i++) { printf("+(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1)))))", x[i] / 2, i, i); } putchar('\n'); for (int i = 1; i < n; i++) putchar('('); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", y[1] / 2, 1, 1); for (int i = 2; i <= n; i++) { printf("+(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1)))))", y[i] / 2, i, i); } putchar('\n'); cin >> n; return 0; }
#include <bits/stdc++.h> using namespace std; string s, t; char tmp[20]; string itostr(int x) { sprintf(tmp, "%d", x); return tmp; } int main() { int n, x, y, tmp; cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y >> tmp; s += "(" + itostr(x / 2) + "*((1-abs((t-" + itostr(i) + ")))+abs((abs((t-" + itostr(i) + "))-1))))"; t += "(" + itostr(y / 2) + "*((1-abs((t-" + itostr(i) + ")))+abs((abs((t-" + itostr(i) + "))-1))))"; if (i) s += ')', t += ')'; s += '+', t += '+'; } s.erase(s.end() - 1), t.erase(t.end() - 1); s = string(n - 1, '(') + s, t = string(n - 1, '(') + t; cout << s << endl << t << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int N; int X[100][2], R[100]; string S[100][2]; string hoge(int i, int x) { char h[1010]; sprintf( h, "(%d*((((0-abs((t-%d)))-abs((t-%d)))+abs(((t-%d)-1)))+abs(((t-%d)+1))))", x, i, i, i, i); return string(h); } void solve() { int i, j, k, l, r, x, y; string s; cin >> N; for (i = 0; i < N; i++) cin >> X[i][0] >> X[i][1] >> R[i]; for (j = 0; j < 2; j++) { for (i = 0; i < N; i++) S[i][j] = hoge(i, X[i][j] / 2); s = S[0][j]; for (i = 1; i < N; i++) s = "(" + s + "+" + S[i][j] + ")"; cout << s << endl; } } int main(int argc, char** argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false); for (i = 0; i < argc - 1; i++) s += argv[i + 1], s += '\n'; for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, l1, l2; char s1[N], s2[N]; int main() { scanf("%d", &n); for (int i = 0; i < n - 1; ++i) s1[i] = s2[i] = '('; l1 = l2 = n - 1; for (int i = 1; i <= n; ++i) { int x, y, r; scanf("%d%d%d", &x, &y, &r); l1 += sprintf(s1 + l1, "(%d*(2-abs((abs((t-(%d+1)))-abs((t-(%d-1)))))))", x / 2, i, i); l2 += sprintf(s2 + l2, "(%d*(2-abs((abs((t-(%d+1)))-abs((t-(%d-1)))))))", y / 2, i, i); if (i != 1) { s1[l1++] = ')'; s2[l2++] = ')'; } if (i != n) { s1[l1++] = '+'; s2[l2++] = '+'; } } s1[l1] = s2[l2] = 0; printf("%s\n%s\n", s1, s2); return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(0.0) * 2.0; const long double eps = 1e-10; const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {1, 1}, {1, -1}, {-1, -1}}; template <class T> inline T abs1(T a) { return a < 0 ? -a : a; } template <typename t, typename t1> t min1(t a, t1 b) { return a < b ? a : b; } template <typename t, typename... arg> t min1(t a, arg... arr) { return min1(a, min1(arr...)); } template <typename t, typename t1> t max1(t a, t1 b) { return a > b ? a : b; } template <typename t, typename... arg> t max1(t a, arg... arr) { return max1(a, max1(arr...)); } inline int jud(double a, double b) { if (abs(a) < eps && abs(b) < eps) return 0; else if (abs1(a - b) / abs1(a) < eps) return 0; if (a < b) return -1; return 1; } template <typename t> inline int jud(t a, t b) { if (a < b) return -1; if (a == b) return 0; return 1; } template <typename it, typename t1> inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) { if (na == 0) return 0; int be = 0, en = na - 1; if (*a <= *(a + na - 1)) { if (f_lb == 0) while (be < en) { int mid = (be + en + 1) / 2; if (jud(*(a + mid), val) != 1) be = mid; else en = mid - 1; } else while (be < en) { int mid = (be + en) / 2; if (jud(*(a + mid), val) != -1) en = mid; else be = mid + 1; } if (f_small && jud(*(a + be), val) == 1) be--; if (!f_small && jud(*(a + be), val) == -1) be++; } else { if (f_lb) while (be < en) { int mid = (be + en + 1) / 2; if (jud(*(a + mid), val) != -1) be = mid; else en = mid - 1; } else while (be < en) { int mid = (be + en) / 2; if (jud(*(a + mid), val) != 1) en = mid; else be = mid + 1; } if (!f_small && jud(*(a + be), val) == -1) be--; if (f_small && jud(*(a + be), val) == 1) be++; } return be; } template <class T> inline T lowb(T num) { return num & (-num); } inline int bitnum(unsigned int nValue) { return __builtin_popcount(nValue); } inline int bitnum(int nValue) { return __builtin_popcount(nValue); } inline int bitnum(unsigned long long nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); } inline int bitnum(long long nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); } inline int bitmaxl(unsigned int a) { if (a == 0) return 0; return 32 - __builtin_clz(a); } inline int bitmaxl(int a) { if (a == 0) return 0; return 32 - __builtin_clz(a); } inline int bitmaxl(unsigned long long a) { int temp = a >> 32; if (temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); } inline int bitmaxl(long long a) { int temp = a >> 32; if (temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); } long long pow(long long n, long long m, long long mod = 0) { if (m < 0) return 0; long long ans = 1; long long k = n; while (m) { if (m & 1) { ans *= k; if (mod) ans %= mod; } k *= k; if (mod) k %= mod; m >>= 1; } return ans; } template <class t1, class t2> inline void add(t1 &a, t2 b, int mod = -1) { if (mod == -1) mod = 1000000007; a += b; while (a >= mod) a -= mod; while (a < 0) a += mod; } template <class t> void output1(t arr) { for (int i = 0; i < (int)arr.size(); i++) cerr << arr[i] << ' '; cerr << endl; } template <class t> void output2(t arr) { for (int i = 0; i < (int)arr.size(); i++) output1(arr[i]); } string str; string jia(string a, string b) { return '(' + a + '+' + b + ')'; } string multi(string a, string b) { return '(' + a + '*' + b + ')'; } string jian(string a, string b) { return '(' + a + '-' + b + ')'; } string gabs(string a) { return "abs(" + a + ')'; } string tostr(int a) { if (a == 0) { return "0"; } string str; while (a) { str = char(a % 10 + 48) + str; a /= 10; } return str; } string ansx, ansy; string justdoit(int t, int v) { string ans; if (t != 0) ans = gabs(jian("t", tostr(t - 1))); else ans = gabs(jia("t", tostr(1))); ans = jia(ans, gabs(jian(tostr(t + 1), "t"))); ans = jian(ans, gabs(jian("t", tostr(t)))); ans = jian(ans, gabs(jian("t", tostr(t)))); ans = multi(tostr(v / 2), ans); cerr << ans << endl; return ans; } int main() { ios_base::sync_with_stdio(0); int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x, y, r; scanf("%d%d%d", &x, &y, &r); if (x % 2) x++; if (y % 2) y++; if (i == 0) { ansx = justdoit(0, x); ansy = justdoit(0, y); } else { ansx = jia(ansx, justdoit(i, x)); ansy = jia(ansy, justdoit(i, y)); } } cout << ansx << endl; cout << ansy << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 52; struct circle { int x, y; } a[N]; int n; void d1(int l, int r) { if (l == r) { printf("(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", a[l].x / 2, l, l); return; } int mid = (l + r) >> 1; printf("("); d1(l, mid); printf("+"); d1(mid + 1, r); printf(")"); } void d2(int l, int r) { if (l == r) { printf("(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", a[l].y / 2, l, l); return; } int mid = (l + r) >> 1; printf("("); d2(l, mid); printf("+"); d2(mid + 1, r); printf(")"); } int main() { scanf("%d", &n); int p; for (int i = 1; i <= n; i++) { scanf("%d%d%d", &a[i].x, &a[i].y, &p); } d1(1, n); puts(""); d2(1, n); puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; int x[50], y[50]; void print_term(int x, int i) { cout << "(" << x / 2 << "*((abs((t-" << i - 1 << "))+abs((t-(" << i << "+1)" << ")))-(abs((t-" << i << "))+abs((t-" << i << ")))))"; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { int r; cin >> x[i] >> y[i] >> r; } for (int i = 1; i < n; ++i) { cout << '('; } print_term(x[0], 1); for (int i = 1; i < n; ++i) { cout << '+'; print_term(x[i], i + 1); cout << ')'; } cout << endl; for (int i = 1; i < n; ++i) { cout << '('; } print_term(y[0], 1); for (int i = 1; i < n; ++i) { cout << '+'; print_term(y[i], i + 1); cout << ')'; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; int x, y, r; string f, g; string chislo(int a) { string ans; if (a == 0) { ans += '0'; return ans; } while (a > 0) { ans += '0' + a % 10; a /= 10; } reverse(ans.begin(), ans.end()); return ans; } int main() { cin >> n; f = ""; g = ""; for (int i = 0; i < n; i++) { cin >> x >> y >> r; x /= 2; y /= 2; string a = ""; string b = ""; a += "(((1-abs((t-"; a += chislo(i); a += ")))+abs((abs((t-"; a += chislo(i); a += "))-1)))*"; a += chislo(x); a += ")"; b += "(((1-abs((t-"; b += chislo(i); b += ")))+abs((abs((t-"; b += chislo(i); b += "))-1)))*"; b += chislo(y); b += ")"; if (f.empty()) { f += a; } else { f = "(" + f; f += "+"; f += a; f += ")"; } if (g.empty()) { g += b; } else { g = "(" + g; g += "+"; g += b; g += ")"; } } cout << f << endl; cout << g << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string get_func(int c) { string res = "(t-" + to_string(c) + ")"; res = "(" + res + "+" + "abs(" + res + "))"; return res; } string solve(vector<int> a) { for (int i = 0; i < (int)a.size(); i++) if (a[i] & 1) a[i] ^= 1; string res = to_string(a[0]); for (int i = 1; i < (int)a.size(); i++) { string cur = "(" + get_func(i - 1) + "-" + get_func(i) + ")"; int diff = (a[i] - a[i - 1]) / 2; string sdiff = diff >= 0 ? (to_string(diff)) : ("(0-" + to_string(-diff) + ")"); cur = "(" + cur + "*" + sdiff + ")"; res = "(" + res + "+" + cur + ")"; } return res; } int main() { int n; scanf("%d", &n); vector<int> vx, vy; for (int i = 0; i < n; i++) { int x, y, r; scanf("%d%d%d", &x, &y, &r); vx.push_back(x); vy.push_back(y); } cout << solve(vx) << endl; cout << solve(vy) << endl; }
#include <bits/stdc++.h> using namespace std; string p; string q; int n; int x[55]; int y[55]; int r[55]; string to(int a) { string s; if (a == 0) { s += "0"; return s; } while (a > 0) { s += char(a % 10) + '0'; a /= 10; } reverse(s.begin(), s.end()); return s; } string ab(string x) { string s = "abs(" + x + ")"; return s; } string sum(string p, string q) { string s = "(" + p + "+" + q + ")"; return s; } string dif(string p, string q) { string s = "(" + p + "-" + q + ")"; return s; } string mult(string p, string q) { string s = "(" + p + "*" + q + ")"; return s; } string t() { return "t"; } int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i] >> r[i]; } string p; p = mult(to((x[1] + 1) / 2), dif(sum(ab(dif(to(50), ab(dif(t(), to(1))))), ab(dif(ab(dif(t(), to(1))), to(1)))), to(49))); for (int i = 2; i <= n; i++) { string q = mult(to((x[i] + 1) / 2), dif(sum(ab(dif(to(50), ab(dif(t(), to(i))))), ab(dif(ab(dif(t(), to(i))), to(1)))), to(49))); p = sum(p, q); } cout << p << '\n'; for (int i = 1; i <= n; i++) x[i] = y[i]; p = mult(to((x[1] + 1) / 2), dif(sum(ab(dif(to(50), ab(dif(t(), to(1))))), ab(dif(ab(dif(t(), to(1))), to(1)))), to(49))); for (int i = 2; i <= n; i++) { string q = mult(to((x[i] + 1) / 2), dif(sum(ab(dif(to(50), ab(dif(t(), to(i))))), ab(dif(ab(dif(t(), to(i))), to(1)))), to(49))); p = sum(p, q); } cout << p << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int x[60], y[60]; void outx(int i) { printf("(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", x[i], i, i); } void outy(int i) { printf("(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", y[i], i, i); } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); x[i] = a / 2; y[i] = b / 2; } for (int i = 1; i <= n - 1; i++) printf("("); outx(1); for (int i = 2; i <= n; i++) { printf("+"); outx(i); printf(")"); } printf("\n"); for (int i = 1; i <= n - 1; i++) printf("("); outy(1); for (int i = 2; i <= n; i++) { printf("+"); outy(i); printf(")"); } printf("\n"); return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/stack:20000000") using namespace std; vector<pair<int, int> > items; void createFunc(int *values, int n, int t, int coef, int c) { if (n <= 0) return; int val = (t + 1) * coef + c; int target = (values[0] - val) / 2; if (target != 0) items.push_back(make_pair(target, t)); createFunc(values + 1, n - 1, t + 1, coef + target * 2, c - (t)*2 * target); } void printNum(int n) { if (n >= 0) cout << n; else cout << "(0-" << (-n) << ")"; } void printFunc(int c, int i) { if (i != items.size() - 1) cout << "("; cout << "((abs((t-" << items[i].second << "))+(t-" << items[i].second << "))*"; printNum(items[i].first); cout << ")"; if (i != items.size() - 1) { cout << "+"; printFunc(c, i + 1); cout << ")"; } } void printFunc(int c) { if (items.size() == 0) cout << c << endl; else if (items.size() == 1) { cout << "(" << c << "+((abs((t-" << items[0].second << "))+(t-" << items[0].second << "))*"; printNum(items[0].first); cout << "))" << endl; } else { if (c != 0) cout << "(" << c << "+"; printFunc(c, 0); if (c != 0) cout << ")" << endl; else cout << endl; } } int n; int x[100], y[100]; int main() { cin >> n; int temp; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> temp; createFunc(x + 1, n - 1, 0, 0, x[0]); printFunc(x[0]); items.clear(); createFunc(y + 1, n - 1, 0, 0, y[0]); printFunc(y[0]); return 0; }
#include <bits/stdc++.h> using namespace std; int x[77], y[77], r[77]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%d", x + i, y + i, r + i); for (int i = 1; i < n; i++) printf("("); for (int i = 1; i <= n; i++) { if (i > 1) printf("+"); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[i] / 2, i, i); if (i > 1) printf(")"); } puts(""); for (int i = 1; i < n; i++) printf("("); for (int i = 1; i <= n; i++) { if (i > 1) printf("+"); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", y[i] / 2, i, i); if (i > 1) printf(")"); } puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; int n; void solve(int *x) { for (int i = 1; i < n; i++) putchar('('); for (int i = 0; i < n; i++) { if (i >= 1) putchar('+'); printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[i] / 2, i, i); if (i >= 1) putchar(')'); } } int x[555], y[555], baka; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d%d", &x[i], &y[i], &baka); solve(x); cout << endl; solve(y); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; int N, X[MAXN], Y[MAXN], R; void ps1(int t) { if (t < 0) cout << t; else cout << "+" << t; } void ps(int t) { if (t < 0) cout << "-(" << -t; else cout << "+(" << t; } void solve(int *A) { cout << "(0"; int slope = 0, cur = 0; for (int i = 0; i < N; i++) { if (A[i] % 2) A[i] += 1; int nslope = A[i] - cur; int k = (nslope - slope) / 2; if (i == N - 1) { cout << "+(0"; } else { cout << "+((0"; } ps(k); cout << "*(t"; ps(1 - i); if (1 - i < 0) cout << "-"; else cout << "+"; cout << "abs((t"; ps1(1 - i); if (i == N - 1) { cout << ")))))"; } else { cout << "))))))"; } slope = nslope; cur = A[i]; cerr << slope << endl; } for (int i = 0; i < N; i++) { cout << ")"; } cout << ")\n"; } int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i] >> R; } solve(X); solve(Y); }
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string X = "0"; string Y = "0"; int px = 0; int py = 0; for (int i = 0; i < n; ++i) { int x, y, r; cin >> x >> y >> r; if (x & 1) --x; if (y & 1) --y; int dx = x - px; int dy = y - py; stringstream xss, yss; xss << (dx >= 0 ? '+' : '-') << "(" << abs(dx / 2) << "*((abs((t-" << i << "))-abs((t-" << (i + 1) << ")))+1))"; yss << (dy >= 0 ? '+' : '-') << "(" << abs(dy / 2) << "*((abs((t-" << i << "))-abs((t-" << (i + 1) << ")))+1))"; X = "(" + X + xss.str() + ")"; Y = "(" + Y + yss.str() + ")"; px += dx; py += dy; } cout << X << "\n"; cout << Y << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> using V = vector<T>; int gcdex(int a, int b, int &x, int &y) { if (a == 0) { x = 0; y = 1; return b; } int x1, y1; int g = gcdex(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; } inline int ADD_MOD(int a, int b) { return (a + b) % 1000000007; } inline int MUL_MOD(int a, int b) { return (int64_t(a) * b) % 1000000007; } inline int SUB_MOD(int a, int b) { return a >= b ? a - b : a + 1000000007 - b; } int DIV_MOD(int a, int b) { int x, y; gcdex(b, 1000000007, x, y); int b1 = (x % 1000000007 + 1000000007) % 1000000007; return MUL_MOD(a, b1); } const long double EPS = 1. / 1e9; inline bool EPS_EQUAL(long double a, long double b) { return abs(a - b) <= EPS; } inline bool EPS_LESS(long double a, long double b) { return b - a > EPS; } inline bool EPS_GREATER(long double a, long double b) { return a - b > EPS; } const int INF = 1e9; string brace(string s) { return "(" + s + ")"; } string add(string a, string b) { return brace(a + "+" + b); } string diff(string a, string b) { return brace(a + "-" + b); } string mul(string a, string b) { return brace(a + "*" + b); } string num(int n) { if (n < 0) { return diff("0", num(-n)); } if (n > 50) { return add("50", num(n - 50)); } return to_string(n); } string pmax(string a, string b) { return brace(add(a, b) + "+abs" + brace(diff(a, b))); } string pmin(string a, string b) { return brace(add(a, b) + "-abs" + brace(diff(a, b))); } string print_step(int val, int k) { return mul(diff(pmin(num(2 * k - 1), pmax("t", num(k - 1))), num(4 * k - 4)), num(val)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(15); int n; cin >> n; string fx, fy; int prevX = 0, prevY = 0; for (int i = 0; i < n; ++i) { int x, y, r; cin >> x >> y >> r; if (x % 2 != 0) { x += 1; } if (y % 2 != 0) { y += 1; } int dx = x - prevX; int dy = y - prevY; prevX = x, prevY = y; string stepX = print_step(dx / 2, i); string stepY = print_step(dy / 2, i); if (i > 0) { fx = add(fx, stepX); fy = add(fy, stepY); } else { fx = stepX; fy = stepY; } } cout << fx << endl; cout << fy << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; int n; void print(int second, int down) { bool neg = (second < 0); if (neg) { printf("((0-%d)*", -second); } else printf("(%d*", second); printf("((t-%d)+abs((t-%d))))", down, down); } void proc(int *a) { if (n == 1) { printf("%d\n", a[0]); return; } printf("(%d+", a[0]); int ly = a[0], der = 0; for (int(i) = (1); (i) < (n); ++(i)) { int ny = a[i]; int second = (ny - (ly + der)) / 2; if (i == n - 1) { print(second, i - 1); } else { printf("("); print(second, i - 1); printf("+"); } der += second + second; ly += der; } for (int(i) = (0); (i) < (n - 2); ++(i)) printf(")"); puts(")"); } pair<int, int> a[59]; int x[59], y[59]; int main() { while (scanf("%d", &n) == 1) { for (int(i) = (0); (i) < (n); ++(i)) { int x, y, r; scanf("%d%d%d", &x, &y, &r); a[i] = pair<int, int>(x, y); } for (int(i) = (0); (i) < (n); ++(i)) { x[i] = a[i].first; y[i] = a[i].second; } proc(x); proc(y); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vvi = vector<vi>; using vii = vector<ii>; using vvii = vector<vii>; const int INF = 2000000000; const ll LLINF = 9000000000000000000; void add_number(int x, vector<char> &outp); void add_jump(int c, vector<char> &vec) { vec.push_back('('); vec.push_back('t'); vec.push_back('-'); add_number(c, vec); vec.push_back(')'); vec.push_back('+'); vec.push_back('a'); vec.push_back('b'); vec.push_back('s'); vec.push_back('('); vec.push_back('('); vec.push_back('t'); vec.push_back('-'); add_number(c, vec); vec.push_back(')'); vec.push_back(')'); } void add_number(int x, vector<char> &outp) { vector<char> st; if (x == 0) st.push_back('0'); while (x > 0) { st.push_back('0' + (x % 10)); x /= 10; } while (st.size() > 0) { outp.push_back(st.back()); st.pop_back(); } } void make_number(int x, vector<char> &outp) { if (x < 0) { outp.push_back('('); outp.push_back('0'); outp.push_back('-'); make_number(-x, outp); outp.push_back(')'); return; } if (x == 0) outp.push_back('0'); else if (x <= 50) { add_number(x, outp); } else { outp.push_back('('); add_number(x % 50, outp); outp.push_back('+'); outp.push_back('('); add_number(50, outp); outp.push_back('*'); make_number(x / 50, outp); outp.push_back(')'); outp.push_back(')'); } } void construct(vi &a) { int pre = 0; vector<char> outp; int add = 0; for (int t = 1; t <= a.size(); ++t) { int val = (t > 1 ? a[t - 2] : 0); val += add; int req = a[t - 1] - val; if (t > 1) { pre++; outp.push_back(')'); outp.push_back('+'); outp.push_back('('); } outp.push_back('('); add_jump(t - 1, outp); outp.push_back(')'); outp.push_back('*'); make_number(req / 2, outp); a[t - 1] = val + 2 * (req / 2); if (t > 1) { outp.push_back(')'); } add += 2 * (req / 2); } pre++; outp.push_back(')'); while (pre--) cout << '('; for (size_t i = 0; i < outp.size(); ++i) cout << outp[i]; cout << endl; } int main() { int n; scanf("%d", &n); vi x(n, 0), y(n, 0), r(n, 0); for (int i = 0; i < n; ++i) { scanf("%d %d %d", &x[i], &y[i], &r[i]); } construct(x); construct(y); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 51; int x[maxn], y[maxn], r[maxn]; int n; void input() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d%d%d", &x[i], &y[i], &r[i]); } void f(int *a) { for (int i = 1; i < n; ++i) printf("("); for (int i = 1; i <= n; ++i) { int k = a[i] / 2; printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", k, i, i); if (i != 1) printf(")"); if (i != n) printf("+"); } printf("\n"); } void solve() { f(x); f(y); } int main() { input(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int n; void go(int arr[]) { for (int i = 0; i < n - 1; i++) { printf("("); } for (int i = 0; i < n; i++) { if (i) { printf("+"); } printf("(%d*(abs((abs((t-%d))-1))-(abs((t-%d))-1)))", arr[i] / 2, i, i); if (i) { printf(")"); } } printf("\n"); } int main() { cin >> n; int x[100]; int y[100]; for (int i = 0; i < n; i++) { cin >> x[i]; cin >> y[i]; int g; cin >> g; } go(x); go(y); return 0; }
#include <bits/stdc++.h> using namespace std; int n, i, x[52], y[52], r[52]; int read() { char c = getchar(); int w = 0; while (c < '0' || c > '9') c = getchar(); while (c <= '9' && c >= '0') { w = w * 10 + c - '0'; c = getchar(); } return w; } void solve(int *a) { for (int i = 1; i < n; i++) printf("("); for (int i = 1; i < n; i++) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", a[i] / 2, i - 1, i - 1); if (i != 1) printf(")"); printf("+"); } printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", a[n] / 2, n - 1, n - 1); if (n != 1) printf(")"); puts(""); } int main() { n = read(); for (i = 1; i <= n; i++) x[i] = read(), y[i] = read(), r[i] = read(); solve(x); solve(y); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 20 + 10; const long long MOD = 1e9 + 7; const int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; inline long long in() { long long x = 0, flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return x * flag; } int n, len; string ansx, ansy; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int x, y, r; scanf("%d%d%d", &x, &y, &r); char nowx[110], nowy[110]; string X = "", Y = ""; sprintf(nowx, "(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", x / 2, i, i); sprintf(nowy, "(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", y / 2, i, i); X = nowx; Y = nowy; if (i == 0) ansx = ansx + X, ansy = ansy + Y; else ansx = "(" + ansx + "+" + X + ")", ansy = "(" + ansy + "+" + Y + ")"; } cout << ansx << endl << ansy << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[100], b[100], c[100], d[100]; int main() { int n, z; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d %d", &a[i], &b[i], &z); } for (int i = 0; i < n; i++) { printf("("); } printf("%d", a[0]); int x = a[0]; for (int i = 1; i < n; i++) { int dx = (a[i] - x) / 2; c[i - 1] += dx; c[i] -= dx; d[i] = dx; x += dx * 2; } for (int i = 0; i < n; i++) { printf("+((0%c%d)%c(%d*abs((t-%d)))))", d[i] >= 0 ? '+' : '-', abs(d[i]), c[i] >= 0 ? '+' : '-', abs(c[i]), i); c[i] = 0; } printf("\n"); for (int i = 0; i < n; i++) { printf("("); } printf("%d", b[0]); x = b[0]; for (int i = 1; i < n; i++) { int dx = (b[i] - x) / 2; c[i - 1] += dx; c[i] -= dx; d[i] = dx; x += dx * 2; } for (int i = 0; i < n; i++) { printf("+((0%c%d)%c(%d*abs((t-%d)))))", d[i] >= 0 ? '+' : '-', abs(d[i]), c[i] >= 0 ? '+' : '-', abs(c[i]), i); } return 0; }
#include <bits/stdc++.h> const int N = 100010; const long long MOD = 1e9 + 7; using namespace std; int n, x[N], y[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%*d", &x[i], &y[i]); for (int i = 1; i <= n - 1; i++) printf("("); for (int i = 1; i <= n; i++) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[i] / 2, i, i); if (i > 1) printf(")"); if (i < n) printf("+"); } printf("\n"); for (int i = 1; i <= n - 1; i++) printf("("); for (int i = 1; i <= n; i++) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", y[i] / 2, i, i); if (i > 1) printf(")"); if (i < n) printf("+"); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int n, y[101], x[101]; vector<string> xs, ys; string constant(int c) { stringstream s; (c < 0) ? s << "(0-" << -c << ")" : s << c; return s.str(); } void print_func(vector<string> &terms, int c) { if (terms.size() == 0) cout << constant(c) << endl; else if (terms.size() == 1) cout << "(" << terms[0] << "+" << constant(c) << ")" << endl; else { for (int i = 0; i < terms.size(); i++) cout << "("; cout << terms[0] << "+"; for (int i = 1; i < terms.size(); i++) cout << terms[i] << ")+"; cout << constant(c) << ")" << endl; } } int main() { cin >> n; for (int i = 0, r; i < n; i++) { cin >> x[i] >> y[i] >> r; if (x[i] % 2) x[i] ? x[i]-- : x[i]++; if (y[i] % 2) y[i] ? y[i]-- : y[i]++; } int c = 0; for (int i = 1; i < n; i++) { stringstream s; int m = (x[i] - x[i - 1]) / 2; s << "(" << constant(m) << "*"; s << "(abs((t-" << i << "))-abs((" << i + 1 << "-t))))"; xs.push_back(s.str()); c -= m; } print_func(xs, x[0] - c); c = 0; for (int i = 1; i < n; i++) { stringstream s; int m = (y[i] - y[i - 1]) / 2; s << "(" << constant(m) << "*"; s << "(abs((t-" << i << "))-abs((" << i + 1 << "-t))))"; ys.push_back(s.str()); c -= m; } print_func(ys, y[0] - c); }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x[51], y[51], r[51]; while (cin >> n) { for (i = 0; i < n; i++) scanf("%d%d%d", &x[i], &y[i], &r[i]); for (i = 1; i < n; i++) printf("("); for (i = 0; i < n; i++) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x[i] / 2, i, i); if (i) printf(")"); if (i != n - 1) printf("+"); } printf("\n"); for (i = 1; i < n; i++) printf("("); for (i = 0; i < n; i++) { printf("(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", y[i] / 2, i, i); if (i) printf(")"); if (i != n - 1) printf("+"); } printf("\n"); } }
#include <bits/stdc++.h> using namespace std; const int S = 53; char buf[1000000], *p1, *p2; inline char gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; } inline int rd() { register int f = 0; register char c = gc(); while (c < 48 || c > 57) c = gc(); while (c > 47 && c < 58) f = f * 10 + (c ^ 48), c = gc(); return f; } int f[S][3]; void slv(int l, int r, int v) { if (l == r) { printf("(%01d*abs(((1-abs((t-%d)))+abs((abs((t-%d))-1)))))", f[l][v] >> 1, l, l); return; } register int m = l + r >> 1; putchar('('), slv(l, m, v), putchar('+'), slv(m + 1, r, v), putchar(')'); } int main() { register int n = rd(), i; for (i = 1; i <= n; ++i) f[i][0] = rd(), f[i][1] = rd(), f[i][2] = rd(); slv(1, n, 0), putchar('\n'), slv(1, n, 1); return 0; }
#include <bits/stdc++.h> using namespace std; long long rdtsc() { long long tmp; asm("rdtsc" : "=A"(tmp)); return tmp; } inline int myrand() { return abs((rand() << 15) ^ rand()); } inline int rnd(int x) { return myrand() % x; } const int INF = (int)1.01e9; const long double EPS = 1e-9; void precalc() {} const int maxn = 50 + 5; int n; int xs[maxn], ys[maxn]; bool read() { if (scanf("%d", &n) < 1) { return 0; } for (int i = 0; i < n; ++i) { int r; scanf("%d%d%d", xs + i, ys + i, &r); } return 1; } void print(int n, int *vals) { string res = ""; for (int i = 0; i < n - 1; ++i) { res += "("; } static char tmp[30]; { sprintf(tmp, "%d", vals[0]); res += tmp; } int a = 0; int last = vals[0]; for (int i = 1; i < n; ++i) { int times = (vals[i] - last - a) / 2; a += times * 2; last += a; if (times >= 0) { res += "+"; } else { res += "-"; times = -times; } assert(times <= 50); sprintf(tmp, "(%d*((t-%d)+abs((t-%d)))))", times, i - 1, i - 1); res += tmp; } printf("%s\n", res.c_str()); } void solve() { print(n, xs); print(n, ys); } int main() { srand(rdtsc()); precalc(); while (1) { if (!read()) { break; } solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; string foo(int t, int x) { char tmp[256]; sprintf(tmp, "(%d*((1-abs((t-%d)))+abs((1-abs((t-%d))))))", x / 2, t, t); string res(tmp); return res; } int main() { int n; scanf("%d", &n); int x, y, r; scanf("%d %d %d", &x, &y, &r); string f = foo(0, x); string g = foo(0, y); for (int i = 1; i < n; i++) { scanf("%d %d %d", &x, &y, &r); f = '(' + f + '+' + foo(i, x) + ')'; g = '(' + g + '+' + foo(i, y) + ')'; } cout << f << endl << g; return 0; }
#include <bits/stdc++.h> using namespace std; struct elem { string s; elem() {} elem(string ins) { s = ins; } elem(int x) { if (x == 0) s = "0"; else { while (x) { s += string(1, char(x % 10 + '0')); x /= 10; } for (int i = 0, j = int(s.size()) - 1; i < j; i++, j--) swap(s[i], s[j]); } } }; elem operator+(elem e1, elem e2) { return "(" + e1.s + "+" + e2.s + ")"; } elem operator-(elem e1, elem e2) { return "(" + e1.s + "-" + e2.s + ")"; } elem operator*(elem e1, elem e2) { return "(" + e1.s + "*" + e2.s + ")"; } elem abs(elem e) { return "abs(" + e.s + ")"; } elem genera(int c, int val) { elem e = elem(c) - elem("t"); e = abs(e + e); e = abs(e - 50); e = abs(e - 24); e = abs(e - 12); e = abs(e - 6); e = abs(e - 3); e = abs(e - 2); e = e - 1; e = e * (val / 2); return e; } int main() { int n; cin >> n; int x, y, r; cin >> x >> y >> r; elem ex = genera(0, x); elem ey = genera(0, y); for (int i = 1; i < n; i++) { cin >> x >> y >> r; ex = ex + genera(i, x); ey = ey + genera(i, y); } cout << ex.s << endl; cout << ey.s << endl; }
#include <bits/stdc++.h> using namespace std; string abs(string a) { return "abs(" + a + ")"; } string add(string a, string b) { return "(" + a + "+" + b + ")"; } string subtract(string a, string b) { return "(" + a + "-" + b + ")"; } string multiply(string a, string b) { return "(" + a + "*" + b + ")"; } string constant(int a) { if (a < 0) return subtract("0", constant(-a)); if (a <= 50) return to_string(a); string res = "0"; while (a > 50) res = add(res, "50"), a -= 50; return add(res, to_string(a)); } string make(vector<int> x) { string res = "0"; int on = 0; vector<int> has; for (int i : x) { string cur = subtract("t", constant(on)); cur = add(cur, abs(cur)); int prev = 0; for (int j = 0; j < on; j++) prev += 2 * (on - j + 1) * has[j]; if (prev % 2 != i % 2) i += 1; prev = (i - prev) / 2; has.push_back(prev); cur = multiply(cur, constant(prev)); on += 1; res = add(res, cur); } return res; } int n; vector<int> x, y; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int a, b; scanf("%d%d%*d", &a, &b); x.push_back(a); y.push_back(b); } printf("%s\n", make(x).c_str()); printf("%s\n", make(y).c_str()); return 0; }
#include <bits/stdc++.h> using namespace std; string B(int i) { return "((1-abs((t-" + to_string(i) + ")))+abs((1-abs((t-" + to_string(i) + ")))))"; } void printcomp(int i, int j) { cout << "(" << i / 2 << "*" << B(j) << ")"; } int main() { int n; vector<int> xs, ys; int r; cin >> n; xs.resize(n); ys.resize(n); for (int c = 0; c < n; c++) { cin >> xs[c] >> ys[c] >> r; if (c) cout << "("; } for (int c = 0; c < n; c++) { if (c) cout << "+"; printcomp(xs[c], c); if (c) cout << ")"; } cout << endl; for (int c = 1; c < n; c++) cout << "("; for (int c = 0; c < n; c++) { if (c) cout << "+"; printcomp(ys[c], c); if (c) cout << ")"; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 53; pair<int, int> a[N]; inline int read() { register int x; cin >> x; return x; } string Left, Mid, Right, ans1, ans2, num; int main() { register int n = read(), r; for (register int i = 0; i < n; ++i) a[i].first = read(), a[i].second = read(), r = read(); Left = "(((1-abs((t-", Mid = ")))+abs((abs((t-", Right = "))-1)))"; for (register int i = 0; i < n - 1; ++i) ans1 += "(", ans2 += "("; for (register int i = 0; i < n; ++i) { num = to_string(i), ans1 += Left + num + Mid + num + Right + "*" + to_string(a[i].first >> 1) + ")", ans2 += Left + num + Mid + num + Right + "*" + to_string(a[i].second >> 1) + ")"; if (i) ans1 += ")", ans2 += ")"; if (i != n - 1) ans1 += "+", ans2 += "+"; } cout << ans1 << endl << ans2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, x, y, r; string f, g, a, b; string to_str(int q); int main() { ios_base::sync_with_stdio(false); cin >> n; f = ""; g = ""; for (int i = 0; i < n; ++i) { cin >> x >> y >> r; x /= 2; y /= 2; a = "(((1-abs((t-" + to_str(i) + ")))+abs((abs((t-" + to_str(i) + "))-1)))*" + to_str(x) + ")"; b = "(((1-abs((t-" + to_str(i) + ")))+abs((abs((t-" + to_str(i) + "))-1)))*" + to_str(y) + ")"; f = (f.length() ? "(" + f + "+" + a + ")" : a); g = (g.length() ? "(" + g + "+" + b + ")" : b); } cout << f << "\n"; cout << g << "\n"; return 0; } string to_str(int q) { string e = (q ? "" : "0"); while (q > 0) { e = char('0' + q % 10) + e; q /= 10; } return e; }
#include <bits/stdc++.h> using namespace std; const int MN = 55; int x[55], y[55]; string part[55]; int main() { ios ::sync_with_stdio(0); cin.tie(0); cout << (fixed) << setprecision(9); int n; while (cin >> n) { for (int i = (1), _b = (n); i <= _b; ++i) { cin >> x[i] >> y[i]; x[i] /= 2; y[i] /= 2; int r; cin >> r; } for (int turn = 0, _a = (2); turn < _a; ++turn) { for (int i = (1), _b = (n); i <= _b; ++i) { stringstream ss; int cur = (turn == 0) ? x[i] : y[i]; ss << '(' << cur << '*' << "((1-abs((t-" << i << ")))+abs((abs((t-" << i << "))-1)))" << ')'; part[i] = ss.str(); } string res = ""; for (int i = (1), _b = (n); i <= _b; ++i) { if (i == 1) res = part[i]; else res = '(' + res + '+' + part[i] + ')'; } cout << res << endl; } } }
#include <bits/stdc++.h> using namespace std; string f(int x, int i) { ostringstream o; o << "(" << (x / 2) << "*((1-abs((t-" << i << ")))+abs((abs((t-" << i << "))-1))))"; return o.str(); } int main() { int n; cin >> n; vector<int> x(n), y(n), r(n); for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> r[i]; vector<string> sx(n), sy(n); for (int i = 0; i < n; ++i) { sx[i] = f(x[i], i); sy[i] = f(y[i], i); } string xx = sx[0]; string yy = sy[0]; for (int i = 1; i < n; ++i) { xx = "(" + xx + "+" + sx[i] + ")"; yy = "(" + yy + "+" + sy[i] + ")"; } cout << xx << endl; cout << yy << endl; }