結果

問題 No.167 N^M mod 10
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-12-02 17:24:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 155 ms / 1,000 ms
コード長 746 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 79,488 KB
実行使用メモリ 57,640 KB
最終ジャッジ日時 2023-10-22 00:12:49
合計ジャッジ時間 6,278 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
56,076 KB
testcase_01 AC 104 ms
57,116 KB
testcase_02 AC 137 ms
57,504 KB
testcase_03 AC 139 ms
57,488 KB
testcase_04 AC 121 ms
57,444 KB
testcase_05 AC 107 ms
57,420 KB
testcase_06 AC 110 ms
57,544 KB
testcase_07 AC 105 ms
55,424 KB
testcase_08 AC 98 ms
56,208 KB
testcase_09 AC 98 ms
56,172 KB
testcase_10 AC 108 ms
57,416 KB
testcase_11 AC 97 ms
56,236 KB
testcase_12 AC 108 ms
57,612 KB
testcase_13 AC 114 ms
57,484 KB
testcase_14 AC 110 ms
57,344 KB
testcase_15 AC 106 ms
57,408 KB
testcase_16 AC 99 ms
56,180 KB
testcase_17 AC 107 ms
57,336 KB
testcase_18 AC 116 ms
57,472 KB
testcase_19 AC 109 ms
57,412 KB
testcase_20 AC 110 ms
57,152 KB
testcase_21 AC 112 ms
57,564 KB
testcase_22 AC 149 ms
57,168 KB
testcase_23 AC 145 ms
57,512 KB
testcase_24 AC 145 ms
57,640 KB
testcase_25 AC 155 ms
57,504 KB
testcase_26 AC 125 ms
57,320 KB
testcase_27 AC 144 ms
57,596 KB
testcase_28 AC 146 ms
57,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String NSt = sc.next();
        String MSt = sc.next();
        int ans = pow(NSt,MSt);
        System.out.println(ans);
    }
    static int pow(String A, String B){
        if(B.equals("0")){
            return 1;
        }
        int x = A.length();
        int N = Integer.parseInt(A.substring(x-1));
        int y = B.length();
        if(y<3){y=3;}
        int M = Integer.parseInt(B.substring(y-3));
        int r = M%4;
        int z = N;
        if(r==0){
            z = (int)(Math.pow(N,4))%10;
        }else if(r!=1){
            z = (int)(Math.pow(N,r))%10;
        }
        return z;
    }
}
0