Self contained fast python  code no import of math library
IntuitionBig_prime = 10**9 + 7
The problem with not using module Big_prime, is that the numbers become so large, multiplication and division are O(M(number of d
# Intuition
Big_prime = 10**9 + 7
The problem with not using module Big_prime, is that the numbers become so large, multiplication and division are O(M(number of digits)) and it is not O(1) anymore.

What to do? use mod Big_prime. But how divide mod Big_prime?

use a** p mod p =a (Fermat little theorem)
therefore a**(p-2) mod p is implementing 1/a  



# Code
```python []
class Solution(object):
    def countAnagrams(self, s):
        Big = 10**9 + 7
        memo = {}
        
        def f(a):
            # Define factorial modulo Big, with base case for 0 and 1.
            if a <= 1:
                return 1
            if a in memo:
                return memo[a]
            memo[a] = (a * f(a-1)) % Big
            return memo[a]
        
        def fact(A):
            summ = 0
            out = 1
            for a in A:
                if a:
                    out = (out * f(a)) % Big
                    summ += a
            # Instead of (f(summ)//out)%Big, we use modular division:
            return (f(summ) * pow(out, Big-2, Big)) % Big

        out = 1
        cur = [0] * 26
        for char in s:
            if char == ' ':
                out = (out * fact(cur)) % Big
                cur = [0] * 26
            else:
                cur[ord(char)-ord('a')] += 1
        return (out * fact(cur)) % Big

```
['Python']