結果

問題 No.167 N^M mod 10
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-20 02:52:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 3,204 ms
コンパイル使用メモリ 71,600 KB
実行使用メモリ 57,720 KB
最終ジャッジ日時 2023-08-18 04:01:49
合計ジャッジ時間 7,181 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,960 KB
testcase_01 AC 122 ms
55,496 KB
testcase_02 AC 151 ms
56,088 KB
testcase_03 AC 151 ms
56,068 KB
testcase_04 WA -
testcase_05 AC 117 ms
55,868 KB
testcase_06 AC 118 ms
55,960 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 115 ms
55,616 KB
testcase_17 AC 115 ms
55,488 KB
testcase_18 AC 116 ms
53,404 KB
testcase_19 AC 116 ms
55,776 KB
testcase_20 AC 116 ms
55,952 KB
testcase_21 AC 119 ms
55,808 KB
testcase_22 AC 159 ms
56,192 KB
testcase_23 AC 159 ms
56,112 KB
testcase_24 AC 151 ms
56,236 KB
testcase_25 AC 149 ms
56,072 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