結果

問題 No.167 N^M mod 10
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-12 01:17:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 175 ms / 1,000 ms
コード長 1,435 bytes
コンパイル時間 2,823 ms
コンパイル使用メモリ 84,140 KB
実行使用メモリ 58,032 KB
最終ジャッジ日時 2023-10-21 23:48:39
合計ジャッジ時間 8,155 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
57,124 KB
testcase_01 AC 137 ms
57,400 KB
testcase_02 AC 172 ms
57,620 KB
testcase_03 AC 175 ms
57,664 KB
testcase_04 AC 175 ms
57,624 KB
testcase_05 AC 132 ms
57,372 KB
testcase_06 AC 137 ms
57,120 KB
testcase_07 AC 134 ms
57,372 KB
testcase_08 AC 134 ms
57,328 KB
testcase_09 AC 134 ms
57,072 KB
testcase_10 AC 135 ms
57,356 KB
testcase_11 AC 137 ms
57,432 KB
testcase_12 AC 136 ms
55,384 KB
testcase_13 AC 132 ms
57,300 KB
testcase_14 AC 129 ms
57,096 KB
testcase_15 AC 129 ms
57,344 KB
testcase_16 AC 128 ms
57,460 KB
testcase_17 AC 129 ms
57,360 KB
testcase_18 AC 129 ms
55,368 KB
testcase_19 AC 127 ms
57,156 KB
testcase_20 AC 130 ms
57,400 KB
testcase_21 AC 132 ms
57,424 KB
testcase_22 AC 169 ms
57,532 KB
testcase_23 AC 174 ms
57,604 KB
testcase_24 AC 168 ms
58,032 KB
testcase_25 AC 162 ms
57,532 KB
testcase_26 AC 145 ms
57,424 KB
testcase_27 AC 168 ms
57,548 KB
testcase_28 AC 171 ms
55,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        String n = koko.next();
        String m = koko.next();
        char nn = n.charAt(n.length()-1);
        char[] mm = new char[2];
        if(m.length()==1&&m.charAt(m.length()-1)=='0'){
            System.out.println(1);
        }else{
            int mnum=0;
            int ans;
            if(m.length()==1){
                mnum = m.charAt(m.length()-1);
            }else{
                mm[0] = m.charAt(m.length()-2);
                mm[1] = m.charAt(m.length()-1);
                String mmm = String.valueOf(mm);
                mnum = Integer.parseInt(mmm);
            }
            int nnum = Character.getNumericValue(nn);
            if(nnum<2||nnum==5||nnum==6){
                ans = nnum;
            }else if(nnum==2){
               ans = (int)(6*(Math.pow(2,mnum%4)))%10;
            }else if(nnum==3){
                ans = (int)(Math.pow(3,mnum%4))%10;
            }else if(nnum==4){
                ans= (int)(6*(Math.pow(4,mnum%2)))%10;
            }else if(nnum==7){
                ans = (int)(Math.pow(7,mnum%4))%10;
            }else if(nnum==8){
                ans = (int)(6*(Math.pow(8,mnum%4))%10);
            }else{
                ans = (int)(Math.pow(9,mnum%2))%10;
            }
            System.out.println(ans);
        }
    }
}




0