#include typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; class ExamOfMath { public: void solve(void) { int N; cin>>N; int d; cin>>d; string form; cin>>form; vector coeff(d+1,0); vector fact(d+1,1); REP(i,d) fact[i+1] = fact[i]*(i+1); // 微分回数 int depth = 0; // 現在の項の情報 ll nowC = 1; int nowD = 0; int nowDepth = 0; // 係数加算のタイミングは + が出現したときなので // 末尾に追加して末尾で強制的に計算させる form += '+'; for (auto c : form) { switch (c) { case '+': if (nowD - nowDepth >= 0) { coeff[nowD - nowDepth] += nowC * (fact[nowD]/fact[nowD-nowDepth]); } nowC = 1; nowD = 0; nowDepth = 0; break; case '*': break; case 'd': ++depth; break; case '{': break; case '}': --depth; break; // 項の開始 case 'x': nowDepth = depth; ++nowD; break; default: nowDepth = depth; nowC = c-'0'; break; } } for (int i = 0; i < d; ++i) cout<solve(); delete obj; return 0; }