• + 0 comments

    C# usin BigInteger (otherwise - russian peasant algorithm):

    private static int longStrToModNum(string a, int m)
    {
        int offs = 18, len = a.Length, idx = len - ((len-1)%offs + 1);
        long fctr = long.Parse($"1{new string('0', (len-1)%offs + 1)}") % m, res = long.Parse(a.Substring(idx)) % m;
        long mod10s = long.Parse($"1{new string('0', offs)}") % m;
        while (idx > 0)
        {
            idx -= offs;
            res = (res + long.Parse(a.Substring(idx, offs)) % m * fctr % m) % m;
            fctr = fctr * mod10s % m;
        }
        return (int)res;
    }
    public static int solve(string a, string b)
    {
        return (int)BigInteger.ModPow(longStrToModNum(a,1000000007), longStrToModNum(b,1000000006), 1000000007);
    }
    

    ...not that speedy, but passing all tests