結果

問題 No.167 N^M mod 10
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-20 03:12:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 744 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 74,856 KB
実行使用メモリ 41,524 KB
最終ジャッジ日時 2024-05-05 10:30:40
合計ジャッジ時間 6,571 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
41,224 KB
testcase_01 AC 100 ms
39,948 KB
testcase_02 AC 142 ms
41,252 KB
testcase_03 AC 126 ms
41,148 KB
testcase_04 WA -
testcase_05 AC 114 ms
41,084 KB
testcase_06 AC 102 ms
40,360 KB
testcase_07 AC 109 ms
41,056 KB
testcase_08 AC 111 ms
41,320 KB
testcase_09 AC 112 ms
41,072 KB
testcase_10 AC 105 ms
40,352 KB
testcase_11 AC 101 ms
40,152 KB
testcase_12 AC 109 ms
41,048 KB
testcase_13 AC 107 ms
40,224 KB
testcase_14 AC 121 ms
40,904 KB
testcase_15 AC 119 ms
41,000 KB
testcase_16 AC 117 ms
40,768 KB
testcase_17 AC 119 ms
40,868 KB
testcase_18 AC 121 ms
41,068 KB
testcase_19 AC 114 ms
41,324 KB
testcase_20 AC 114 ms
40,932 KB
testcase_21 AC 104 ms
39,948 KB
testcase_22 AC 143 ms
41,156 KB
testcase_23 AC 143 ms
41,228 KB
testcase_24 AC 144 ms
41,040 KB
testcase_25 AC 142 ms
41,056 KB
testcase_26 AC 128 ms
41,200 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String NSt = sc.next();
        int x = NSt.length();
        long N = Long.parseLong(NSt.substring(x-1));
        String MSt = sc.next();
        int y = MSt.length();
        if(y<3){
            y=3;
        }
        long M = Long.parseLong(MSt.substring(y-3));
        long r = powmod(N,M);
        System.out.println(r);
    }
    static long powmod(long a, long b){
        a%=10;
        long x=1;
        if(b==0){
            return 1;
        }else if(b%2==0){
            x = powmod(a*a%10, b/2)%10;
        }else{
            x = a*powmod(a*a%10, b/2)%10;
        }
        return x;
    }
}
0