$n = a_0 + a_1 + a_2 + … + a_k$
$m = a_0(n+1)^0 + a_1(n+1)^1 + a_2(n+1)^2 + \dots + a_k(n+1)^k$
m视为(n+1)进制 进制转换取得$a_0 \dots a_k$
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int a[N];
int main()
{
int n,m; scanf("%d %d",&n,&m);
int res = m; int l = 0;
while(res)
{
// printf("%d\n",res%11);
a[l++] = res % (n+1);
res = res / (n+1);
}
for(int i=l-1;i>=0;i--)
{
// printf("%d\n",a[i]);
if(a[i]>1&&i>1){
printf("%dx^%d+",a[i],i);
}else if(a[i] == 1&&i>1){
printf("x^%d+",i);
}else if(a[i] > 1 && i == 1){
printf("%dx+",a[i]);
}else if(a[i] == 1 && i == 1){
printf("x+");
}
if(a[i]>=1&&i == 0){
printf("%d\n",a[i]);
}
}
return 0;
}