結果

問題 No.1595 The Final Digit
ユーザー merlinmerlin
提出日時 2021-07-09 22:14:58
言語 Java19
(openjdk 21)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,269 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 74,344 KB
実行使用メモリ 49,548 KB
最終ジャッジ日時 2023-09-14 09:27:45
合計ジャッジ時間 4,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,328 KB
testcase_01 AC 44 ms
49,368 KB
testcase_02 AC 44 ms
49,424 KB
testcase_03 AC 45 ms
49,332 KB
testcase_04 AC 45 ms
49,548 KB
testcase_05 AC 45 ms
49,372 KB
testcase_06 AC 45 ms
49,300 KB
testcase_07 AC 45 ms
49,468 KB
testcase_08 AC 45 ms
49,324 KB
testcase_09 AC 45 ms
49,280 KB
testcase_10 AC 44 ms
49,144 KB
testcase_11 AC 44 ms
49,488 KB
testcase_12 AC 44 ms
49,312 KB
testcase_13 AC 45 ms
49,420 KB
testcase_14 AC 44 ms
49,420 KB
testcase_15 AC 44 ms
49,248 KB
testcase_16 AC 44 ms
49,212 KB
testcase_17 AC 44 ms
49,400 KB
testcase_18 AC 45 ms
49,472 KB
testcase_19 AC 44 ms
47,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int p=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]),r=Integer.parseInt(s[2]);
        int ans[][]=power(Long.parseLong(s[3])-4);
        int f[][]={{r%M},{q%M},{p%M}};
        ans=multiply(ans,f);
        System.out.println(ans[0][0]);
    }

    static int M=10;
    static int[][] power(long n)
    {
        int a[][]={{1,1,1},{1,0,0},{0,1,0}},res[][]=new int[3][3];
        int i;
        for(i=0;i<3;i++) Arrays.fill(res[i],1);

        while(n!=0)
        {
            if(n%2==1) res=multiply(res,a);
            n>>=1;
            a=multiply(a,a);
        }
        return res;
    }

    static int[][] multiply(int a[][],int b[][])
    {
        int i,j,k,ans[][]=new int[a.length][b[0].length];
        //System.out.println(a.length+" "+a[0].length+" "+b.length+" "+b[0].length);
        for(i=0;i<a.length;i++)
        for(j=0;j<b[0].length;j++)
        for(k=0;k<a[0].length;k++)
        ans[i][j]=(ans[i][j]+a[i][k]*b[k][j]%M)%M;
        return ans;
    }
}
0