提交时间:2023-12-31 08:54:47
运行 ID: 35306
#include <algorithm> #include <iostream> #include <string> using namespace std; struct node { long long a; long long b; } s[1010]; struct nodee { string a; long long b[10010]; int lb; } p[1010]; string q; int w; long long asi, n, t[10010], k, y[10010], m[10010], r[10010], a[10010]; bool cmp(node a1, node a2) { return (a1.a * a1.b) < (a2.a * a2.b); } void s2(int i, int t, int y) { int tt, t2; while (t != 0) { tt = t % 10; t = t / 10; (p[i].a).push_back(tt + '0'); } int k = 0; while (y != 0) { t2 = y % 10; y = y / 10; (p[i].b)[k] = t2; ++k; } p[i].lb = k; } int mul(long long tt[], int x, int l) { for (int j = 0; j < l; j++) { tt[j] = tt[j] * x; } int len = l + 5; for (int i = l; i < l + 5; i++) { tt[i] = 0; } for (int j = 0; j < l + 5; j++) { if (j >= (l - 1) && tt[j] < 10) { len = len - ((l + 5) - j) + 1; break; } if (tt[j] >= 10) { tt[j + 1] = tt[j + 1] + tt[j] / 10; tt[j] = tt[j] % 10; } } return len; } int div(long long t[], int lt, int a, long long r[10010]) { int cur = 0,k = lt - 1,lr = 0; while(k >= 0){ cur = cur * 10 + t[k]; if(cur >= a){ r[lr] = int(cur / a); cur = cur - (int(cur / a) * a); lr ++; } else { r[lr] = 0; lr ++; } k --; } for(int i = 0;i < (lr / 2);i ++){ int k = r[lr - i - 1]; r[lr - i - 1] = r[i]; r[i] = k; } bool f = false; for(int i = lr - 1;i >= 0;i --){ if(r[i] != 0 && f == false){ lr = i + 1; break; } } return lr; } bool cmp_adv(long long a[], int len1, long long b[], int len2) { if (len2 > len1) { return true; } else if (len2 < len1) { return false; } for (int i = len2 - 1; i >= 0; i--) { if (b[i] > a[i]) { return true; } else if(b[i] < a[i]) { return false; } } return false; } int main() { cin >> n; cin >> q >> w; long long ma = 0, cnt = 0; for (long long i = 1; i <= n; i++) { cin >> s[i].a >> s[i].b; ma = max(s[i].b, ma); } sort(s + 1, s + 1 + n, cmp); p[0].a = q; int k = 0, t2 = 0; while (w != 0) { t2 = w % 10; w = w / 10; (p[0].b)[k] = t2; ++k; } p[0].lb = k; for (int i = 1; i <= n; i++) { s2(i, s[i].a, s[i].b); } k = 0; for (int i = 0; i < (p[k].a).size(); i++) { t[i] = (p[k].a[(p[k].a).size() - i - 1] - '0'); } int len = (p[k].a).size(); for (long long i = 1; i <= n; i++) { for (int j = 0; j < len; j++) { m[j] = t[j]; } int len2 = div(m, len, s[i].b, r); len = mul(t, s[i].a, len); bool f = cmp_adv(y, cnt, r, len2); if (f == true) { for (int j = 0; j < len2; j++) { y[j] = r[j]; r[j] = 0; } cnt = len2; } } for (int i = cnt - 1; i >= 0; i--) { cout << y[i]; } cout << endl; return 0; }