Using lucas theorem(lucas theorem code generated from gpt)

```java []
class Solution {
    public boolean hasSameDigits(String s) {
        int n=s.length();
        int m=n-2;
        int a=0;
        int b=0;
        for(int i=0;i<s.length()-1;i++){
           int bc=f(m,i);
           System.out.println(bc);
           a=(a+bc*(s.charAt(i)-'0'));
           b=(b+bc*(s.charAt(i+1)-'0'));
        }
        return a%10==b%10;
    }
    public int f(int m,int j){
        int a=l(m,j,5);
        int b=l(m,j,2);
        for(int i=0;i<=9;i++){
            if((i%2==b)&&(i%5==a)){
                return i;
            }
        }
        return 0;
    }
     public int power(int x, int y, int p) {
        int res = 1;
        x = x % p;
        while (y > 0) {
            if ((y & 1) == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    // Function to compute modular inverse of n under modulo p
    // Using Fermat's Little Theorem: n^(p-2) % p is the inverse of n modulo p when p is prime
    public int modInverse(int n, int p) {
        return power(n, p - 2, p);
    }

    // Function to compute nCr % p using factorials and modular inverses
    public int nCrModP(int n, int r, int p) {
        if (r > n)
            return 0;
        if (r == 0)
            return 1;

        int[] fact = new int[(int)n + 1];
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = (fact[i - 1] * i) % p;
        }
        int result = fact[(int)n];
        result = (result * modInverse(fact[(int)r], p)) % p;
        result = (result * modInverse(fact[(int)(n - r)], p)) % p;
        return result;
    }

    // Lucas' Theorem implementation to compute C(n, r) % p
    public int l(int n, int r, int p) {
        if (r == 0)
            return 1;
        return (l(n / p, r / p, p) * nCrModP(n % p, r % p, p)) % p;
    }
    //39024
    // 3 +9  9+0 0+2 2+4
    // 3+9+9+0 9+0+0+2  0+2+2+4
    //3+9+9+0+9+0+0+2   9+0+0+2+0+2+2+4
}
```
['Java']