結果

問題 No.147 試験監督(2)
ユーザー mbanmban
提出日時 2017-09-05 16:41:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 752 ms / 2,000 ms
コード長 1,914 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 105,856 KB
実行使用メモリ 22,016 KB
最終ジャッジ日時 2024-04-24 14:00:53
合計ジャッジ時間 4,696 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 744 ms
22,016 KB
testcase_01 AC 752 ms
22,016 KB
testcase_02 AC 745 ms
22,016 KB
testcase_03 AC 25 ms
17,920 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

class Magatro
{
    static void Main()
    {
        new Magatro().Solve();
    }
    
    private const int Mod=1000000007;
    
    private long[,] M(long[,] a,long[,] b)
    {
        var res=new long[2,2];
        res[0,0]=(a[0,0]*b[0,0])+(a[0,1]*b[1,0]);
        res[1,0]=(a[1,0]*b[0,0])+(a[1,1]*b[1,0]);
        res[0,1]=(a[0,0]*b[0,1])+(a[0,1]*b[1,1]);
        res[1,1]=(a[1,0]*b[0,1])+(a[1,1]*b[1,1]);
        res[0,0]%=Mod;
        res[1,0]%=Mod;
        res[0,1]%=Mod;
        res[1,1]%=Mod;
        return res;
    }
    
    private long Fib(long n)
    {
        long[,] ans=null;
        long[,]a={{1,1},{1,0}};
        while(n>0)
        {
           if(n%2==1)
           {
               if(ans==null)
               {
                   ans=a;
               }
               else
               {
                  ans=M(ans,a); 
               }
           }
           n/=2;
           a=M(a,a);
        }
        return (ans[0,0]+ans[0,1])%Mod;
    }
    
    private long Modulo(string s,long mod)
    {
        long res=0;
        foreach(char c in s)
        {
            res*=10;
            res+=(c-'0');
            res%=mod;
        }
        return res;
    }
    
    private long Pow(long x,long y)
    {
        long res=1;
        x%=Mod;
        if(x==0)return 0;
        while(y>0)
        {
            if(y%2==1)
            {
                res*=x;
                res%=Mod;
            }
            y/=2;
            x*=x;
            x%=Mod;
        }
        return res;
    }
    
    public void Solve()
    {
        long result=1;
        int N=int.Parse(Console.ReadLine());
        for(int i=0;i<N;i++)
        {
            var l=Console.ReadLine().Split(' ');
            var c=long.Parse(l[0]);
            var d=Modulo(l[1],Mod-1);
            result*=Pow(Fib(c),d);
            result%=Mod;
        }
        Console.WriteLine(result);
    }
}
0