// 2009アジア地区予選 F : Chemist's Math #include #include #include #include #include using namespace std; int pos; string str; map idx; int gcd(int a, int b){ return a%b ? gcd(b, a%b) : b; } int lcm(int a, int b){ return a/gcd(a,b)*b; } vector getCof(){ vector res(idx.size(), 0); if(str[pos]=='+'||str[pos]=='-'||str[pos]=='.'||str[pos]==')') return res; if(str[pos]=='('){ pos++; res = getCof(); pos++; } else { string t; t += str[pos++]; if(pos next = getCof(); for(int i=0;i> str){ if(str == ".") break; int size = 0; idx.clear(); for(int i=0;i > v(size); while(str[pos]!='.'){ if(str[pos]=='+') pos++; if(str[pos]=='-') { rev = true; pos += 2; } vector cof = getCof(); for(int i=0;i