A-Uint47 calculator (rapid multiplication)
Meaning of the questions:
The definition of a bunch of variables and then add or subtract, multiply and divide operations
Ideas:
This question is difficult to place in the multiplication, would exceed the scope of a long long so they need to quickly multiply (similar principle with fast power)
#include<iostream> #include<algorithm> #include<vector> #include<map> #include<string> #define Endl endl using namespace std; typedef long long ll; const ll mod=1ll<<47; map<string,ll> m; string s1,s2,s3; ll qm(ll a,ll b) { ll ans=0; while(b){ if(b%2) ans=(ans+a)%mod; a=(a+a)%mod; b/=2; } return ans; } int main() { ll num; while(cin>>s1>>s2){ if(s1=="def") cin>>num; else{ cin>>s3; if(s1=="add") num=(m[s2]+m[s3])%mod; if(s1=="sub") num=(m[s2]-m[s3]+mod)%mod; if(s1=="mul") num=qm(m[s2],m[s3]); if(s1=="div") num=m[s2]/m[s3]; if(s1=="mod") num=m[s2]%m[s3]; } if(num<0) num+=mod; m[s2]=num; cout<<s2<<" = "<<num<<endl; } return 0; }