C++ || Math || Modulo Multiplicative Inverse || Permutations
Here, for all words we can find distinct permutations and than for distinct permutations for whole string we have to multiply all distinct permutations that can
* Here, for all words we can find distinct permutations and than for distinct permutations for whole string we have to multiply all distinct permutations that can be made from each words.\n* For `too` there are three possible permutations `1.too  2. oot 3. oto` .\n* For finding distinct permutations ,` n! / r1! * r2! ... rn! `, where n is the size of the string and r1 to rn is frequency of the repetitive characters.\n* ` s = "too hot"` i.e for `too = 3! / 2!  = 3`, `hot = 3! = 6`, so answer is  3 * 6 = 18.\n* For dividing by factorial we can use modulo multiplicative inverse.\n\n```\nclass Solution {\npublic:\n    const static int mod = 1e9+7,N = 1e5+10;\n    long long fact[N];\n    long long power(long long x,int y,int mod){\n        long long ans = 1;\n        x = x%mod;\n        while(y >0){\n            if(y&1){\n                ans = (ans*x)%mod;\n            }\n            y>>=1;\n            x = (x*x)%mod;\n        }\n        return ans;\n    }\n    long long modInverse(long long n,int mod){\n        return power(n,mod-2,mod);\n    }\n    void init(){\n        fact[0] = 1;\n        for(int i=1;i<N;i++){\n            fact[i] = (fact[i-1]*i)%mod;\n        }\n    }\n    int countAnagrams(string s){\n        init();\n        int n = s.size();\n        vector<string> tmp;\n        string val = "";\n        for(int i=0;i<n;i++){\n            if(s[i]==\' \'){\n                if(val!="") tmp.push_back(val);\n                val = "";\n            }\n            else{\n                val.push_back(s[i]);\n            }\n        }\n        if(val!="") tmp.push_back(val);\n        long long ans = 1;\n        for(auto &ele:tmp){\n            cout<<ele<<" ";\n            unordered_map<char,int> mp;\n            for(int i=0;i<ele.size();i++){\n                mp[ele[i]]++;\n            }\n            ans = (ans*fact[(int)ele.size()])%mod;\n            for(auto &pr:mp){\n                long long inv = modInverse(fact[pr.second],mod)%mod;\n                ans = (ans*inv)%mod;\n            }\n        }\n        return ans;\n    }\n};\n```
['Math', 'C']