modulo multiplicative inverse using binary exponentiation easy c++ solution
\n// modulo multiplicative inverse using binary exponentiation for better understanding\n//https://youtu.be/Gd9w8m-klho\n# Code\n\nusing ll=long long;\nclass So
\n// modulo multiplicative inverse using binary exponentiation for better understanding\n//https://youtu.be/Gd9w8m-klho\n# Code\n```\nusing ll=long long;\nclass Solution {\npublic:\nconst int N=1e5+1;\n        ll mod=1e9+7;\n    vector<ll> precompute;\n    ll temp=1;\n    void fun(){\n    for(int i=1;i<N;i++){\n        temp=((temp%mod)*i)%mod;\n        precompute.push_back(temp);\n    }\n    }\n    ll binaryexp(int a,int b,int m){\n        ll res=1;\n        while(b>0){\n            if(b%2==1){\n                res=((1ll)*res*a)%m;\n            }\n            a=((1ll)*a*a)%mod;\n            b=b>>1;\n        }\n        return res;\n    }\n\n    int countAnagrams(string s) {\n        int n=s.size();\n        stringstream s1(s);\n          precompute.push_back(1);\n        string word;\n        fun();\n        vector<ll> sum;\n            ll ans=1;\n        while(s1>>word){\n            unordered_map<char,ll> m;\n            for(auto &j:word){\n                m[j]++;\n            }\n            int n1=word.size();\n          long long temp1=precompute[n1];\n            ll temp2=1;\n            for(auto &j1:m){\n                if(j1.second>1){\n                    ll k=j1.second;\n                    temp2=((temp2%mod)*precompute[k])%mod;\n        \n                }\n            }\n         \n         ll den=binaryexp(temp2,mod-2,mod); //denominator\n         \n         ll proeach=((temp1%mod)*den)%mod;\n           ans=((ans%mod)*proeach)%mod;\n             // cout<<temp2<<" "<<den<<" "<<proeach<<" "<<ans<<endl;\n     \n        }\n    \n    return ans%mod;\n        \n    }\n};\n```
['C++']