結果

問題 No.167 N^M mod 10
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-20 02:52:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 75,416 KB
実行使用メモリ 41,696 KB
最終ジャッジ日時 2024-05-05 10:29:09
合計ジャッジ時間 6,229 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
41,596 KB
testcase_01 AC 99 ms
40,404 KB
testcase_02 AC 126 ms
41,300 KB
testcase_03 AC 143 ms
41,360 KB
testcase_04 WA -
testcase_05 AC 108 ms
40,932 KB
testcase_06 AC 100 ms
40,048 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 108 ms
41,376 KB
testcase_17 AC 108 ms
41,468 KB
testcase_18 AC 116 ms
41,684 KB
testcase_19 AC 115 ms
41,148 KB
testcase_20 AC 107 ms
41,144 KB
testcase_21 AC 106 ms
41,164 KB
testcase_22 AC 138 ms
41,484 KB
testcase_23 AC 139 ms
41,696 KB
testcase_24 AC 137 ms
41,420 KB
testcase_25 AC 139 ms
41,580 KB
testcase_26 RE -
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();
        long N = Long.parseLong(NSt.substring(NSt.length()-1));
        String MSt = sc.next();
        long M = Long.parseLong(MSt.substring(MSt.length()-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