結果

問題 No.167 N^M mod 10
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-20 03:12:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 744 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 72,228 KB
実行使用メモリ 58,872 KB
最終ジャッジ日時 2023-08-18 04:03:07
合計ジャッジ時間 6,941 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,416 KB
testcase_01 AC 111 ms
55,904 KB
testcase_02 AC 146 ms
56,448 KB
testcase_03 AC 145 ms
57,156 KB
testcase_04 WA -
testcase_05 AC 113 ms
56,260 KB
testcase_06 AC 111 ms
56,000 KB
testcase_07 AC 115 ms
55,676 KB
testcase_08 AC 113 ms
55,892 KB
testcase_09 AC 112 ms
55,808 KB
testcase_10 AC 112 ms
56,024 KB
testcase_11 AC 111 ms
55,436 KB
testcase_12 AC 113 ms
55,652 KB
testcase_13 AC 112 ms
56,396 KB
testcase_14 AC 114 ms
55,756 KB
testcase_15 AC 113 ms
55,932 KB
testcase_16 AC 115 ms
55,960 KB
testcase_17 AC 114 ms
56,220 KB
testcase_18 AC 112 ms
56,116 KB
testcase_19 AC 112 ms
55,960 KB
testcase_20 AC 113 ms
56,244 KB
testcase_21 AC 114 ms
55,800 KB
testcase_22 AC 154 ms
56,872 KB
testcase_23 AC 145 ms
56,644 KB
testcase_24 AC 154 ms
56,220 KB
testcase_25 AC 154 ms
57,060 KB
testcase_26 AC 129 ms
56,268 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