Matrix power algorithm implemented and one contest task at codeforces.