結果

問題 No.167 N^M mod 10
ユーザー tentententen
提出日時 2022-10-13 10:54:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 55 ms / 1,000 ms
コード長 1,454 bytes
コンパイル時間 1,927 ms
コンパイル使用メモリ 74,160 KB
実行使用メモリ 50,568 KB
最終ジャッジ日時 2023-09-08 19:01:05
合計ジャッジ時間 5,161 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,244 KB
testcase_01 AC 42 ms
49,252 KB
testcase_02 AC 55 ms
50,372 KB
testcase_03 AC 54 ms
50,552 KB
testcase_04 AC 55 ms
50,180 KB
testcase_05 AC 44 ms
49,308 KB
testcase_06 AC 47 ms
49,380 KB
testcase_07 AC 44 ms
49,084 KB
testcase_08 AC 44 ms
49,168 KB
testcase_09 AC 43 ms
49,124 KB
testcase_10 AC 45 ms
49,532 KB
testcase_11 AC 42 ms
49,008 KB
testcase_12 AC 43 ms
49,124 KB
testcase_13 AC 44 ms
49,116 KB
testcase_14 AC 42 ms
49,392 KB
testcase_15 AC 42 ms
49,128 KB
testcase_16 AC 42 ms
47,132 KB
testcase_17 AC 42 ms
49,392 KB
testcase_18 AC 43 ms
49,496 KB
testcase_19 AC 44 ms
49,280 KB
testcase_20 AC 44 ms
49,492 KB
testcase_21 AC 42 ms
49,488 KB
testcase_22 AC 54 ms
50,252 KB
testcase_23 AC 53 ms
50,548 KB
testcase_24 AC 54 ms
50,568 KB
testcase_25 AC 52 ms
50,300 KB
testcase_26 AC 48 ms
47,180 KB
testcase_27 AC 52 ms
50,332 KB
testcase_28 AC 54 ms
50,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        String s = sc.next();
        int n = s.charAt(s.length() - 1) - '0';
        char[] values = sc.next().toCharArray();
        int ans = 1;
        int base = n;
        for (int i = values.length - 1; i >= 0; i--) {
            ans *= pow(base, values[i] - '0');
            ans %= 10;
            base = pow(base, 10);
        }
        System.out.println(ans);
    }
    
    static int pow(int x, int p) {
        int ans = 1;
        for (int i = 0; i < p; i++) {
            ans *= x;
            ans %= 10;
        }
        return ans;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0