Combinatorics
Code


# Code
```python3 []
@cache
def comb2(a,b):
    res = 1
    while a > 0 or b > 0:
        a1 = a % 2
        b1 = b % 2
        if a1>=b1:
            res *= comb(a1,b1) 
        else: return 0
        a = a // 2
        b = b // 2
        res = res % 2
    return res
@cache
def comb5(a,b):
    res = 1
    while a > 0 or b > 0:
        a1 = a % 5
        b1 = b % 5
        if a1>=b1:
            res *= comb(a1,b1) 
        else: return 0
        a = a // 5
        b = b // 5
        res = res % 5
    return res




class Solution:
    def hasSameDigits(self, s: str) -> bool:
        N = len(s)
        a2,b2,a5,b5 = 0,0,0,0
        for i in range(N-1):
            p = int(s[i])
            q = int(s[i+1])
            a2 = (a2 + p*comb2(N-2,i)) % 2
            b2 = (b2 + q*comb2(N-2,i)) % 2
            a5 = (a5 + p*comb5(N-2,i)) % 5
            b5 = (b5 + q*comb5(N-2,i)) % 5
        return a2==b2 and a5==b5
```
['Combinatorics', 'Python3']