提交时间:2024-08-20 22:04:02

运行 ID: 173609

#include <bits/stdc++.h> using namespace std; string Mul(string a, string b) { string ans(b.size()+a.size(),'0'); for (int i=0; i<b.size(); i++) { int now = 0; for (int j=0; j<a.size(); j++) { now=(a[j]-'0')*(b[i]-'0')+(ans[i+j]-'0')+now/10; ans[i+j]=now%10+'0'; if (j==a.size()-1) ans[i+j+1]=now/10+'0'; } } if (ans[b.size()+a.size()-1]=='0') ans.erase(b.size()+a.size()-1,1); return ans; } string Expo(string R, int n) { if (n == 1) return R; string ans = "1", base = R; for(; n != 0; n>>=1) { if (n & 1) ans = Mul(ans, base); base = Mul(base, base); } return ans; } int main() { freopen("debt.in","r",stdin); freopen("debt.out","w",stdout); string R, Ans; int n; while (cin>>R>>n) { if (n!=0) { for (int i=0; R[i]!='.' && R[i]=='0'; R.erase(i,1)); reverse(R.begin(), R.end()); for(int i=0; R[0]=='0'; R.erase(0,1)); int pos = R.find('.'); R.erase(pos, 1); Ans=Expo(R, n); int len = pos*n; if (len>=Ans.size()) { int O=len-Ans.size(); while(O--) Ans+='0'; Ans+='.'; } else Ans.insert(len,1,'.'); if (Ans[0]=='.') Ans.erase(0,1); reverse(Ans.begin(), Ans.end()); cout<<(Ans.size()==0?"0":Ans)<<endl; } else cout<<"1\n"; } return 0; }