https://vjudge.net/contest/249960#problem/A
要注意:ll 64位。mul操作时要用快速乘,不然会超精度。add操作时要取模。
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
map<string,ll>mp;
ll mod=1LL<<47;
ll mul(ll a,ll b)
{ll ans=0;while(b){if(b%2) ans=(ans+a)%mod;b>>=1;a=(a+a)%mod;}return ans%mod;
}
int main()
{string flag;while(cin>>flag){if(flag=="def"){string a;ll num;cin>>a>>num;mp[a]=num;cout<<a<<" = "<<mp[a]<<endl;continue;}if(flag=="sub"){string a,b;cin>>a>>b;mp[a]=(mp[a]-mp[b]+mod)%mod;cout<<a<<" = "<<mp[a]<<endl;continue;}if(flag=="mul"){string a,b;cin>>a>>b;mp[a]=mul(mp[a],mp[b]);cout<<a<<" = "<<mp[a]<<endl;continue;}if(flag=="add"){string a,b;cin>>a>>b;mp[a]=(mp[a]+mp[b])%mod;cout<<a<<" = "<<mp[a]<<endl;continue;}if(flag=="div"){string a,b;cin>>a>>b;mp[a]=mp[a]/mp[b];cout<<a<<" = "<<mp[a]<<endl;continue;}if(flag=="mod"){string a,b;cin>>a>>b;mp[a]=mp[a]%mp[b];cout<<a<<" = "<<mp[a]<<endl;continue;}}return 0;
}