#include<bits/stdc++.h>
using namespace std;
struct node{
long long l,r,val;
}a[1010];
long long n;
int cheng[5000];
int chu[5000];
int ca[5000],da[5000];
bool greater_eq(int a[], int b[], int last_dg, int len) {
if (a[last_dg + len] != 0) return true;
for (int i = len - 1; i >= 0; --i) {
if (a[last_dg + i] > b[i+1]) return true;
if (a[last_dg + i] < b[i+1]) return false;
}
return true;
}
void div(int a[], int b[], int c[], int d[]) {
int la=a[0], lb=b[0];
if (lb == 0) {
puts("> <");
return;
}
for (int i = 0; i <= la; ++i) d[i] = a[i];
for (int i = la - lb + 1; i >= 1; --i) {
while (greater_eq(d, b, i, lb)) {
for (int j = 1; j <= lb; ++j) {
d[i + j - 1] -= b[j];
if (d[i + j - 1] < 0) {
d[i + j] -= 1;
d[i + j - 1] += 10;
}
}
c[i] += 1;
}
}
int i=la - lb + 1;
while(c[i]==0){
i--;
}
for (; i >= 1; --i){
cout<<c[i];
}
}
int main(){
cin>>n;
n++;
for(int i=1;i<=n;i++){
cin>>a[i].l>>a[i].r;
a[i].val=a[i].l*a[i].r;
}
sort(a+2,a+n+1, [](node a, node b){
return a.val<b.val;
});
memset(cheng,0,sizeof(cheng));
cheng[1]=1;
cheng[0]=1;
for(int i=1;i<n;i++){
for(int j=1;j<=cheng[0];j++){
cheng[j]*=a[i].l;
}
for(int j=1;j<=cheng[0];j++){
cheng[j+1]+=cheng[j]/10;
cheng[j]%=10;
}
while(cheng[cheng[0]+1]>0){
cheng[0]++;
cheng[cheng[0]+1]+=cheng[cheng[0]]/10;
cheng[cheng[0]]%=10;
}
}
chu[1]=1;
chu[0]=1;
int i=1;
while(a[n].r){
chu[i]=a[n].r%10;
a[n].r/=10;
i++;
}
div(cheng,chu,ca,da);
return 0;
}
https://www.luogu.com.cn/record/228622892