Example #1
0
    static object Solve()
    {
        var(n, m)            = Read2();
        ModuloMatrixHelper.M = m;

        var a = new long[2, 2];

        a[0, 0] = a[0, 1] = a[1, 0] = 1;

        a = ModuloMatrixHelper.MPow(a, n - 1);
        return(a[1, 0]);
    }
Example #2
0
    static object Solve()
    {
        var(n, b, k) = ((long, int, int))Read3L();
        var cs = Read();

        var m = new long[b, b];

        foreach (var c in cs)
        {
            for (int j = 0; j < b; j++)
            {
                m[(10 * j + c) % b, j]++;
            }
        }

        var dp = new long[b];

        dp[0] = 1;

        m  = ModuloMatrixHelper.MPow(m, n);
        dp = ModuloMatrixHelper.MMul(m, dp);
        return(dp[0]);
    }