結果

問題 No.167 N^M mod 10
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-20 03:09:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 786 bytes
コンパイル時間 4,472 ms
コンパイル使用メモリ 72,480 KB
実行使用メモリ 56,680 KB
最終ジャッジ日時 2023-08-18 04:02:21
合計ジャッジ時間 7,002 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,024 KB
testcase_01 AC 119 ms
55,764 KB
testcase_02 AC 154 ms
56,324 KB
testcase_03 AC 153 ms
56,680 KB
testcase_04 WA -
testcase_05 AC 121 ms
55,564 KB
testcase_06 AC 120 ms
55,744 KB
testcase_07 AC 118 ms
55,608 KB
testcase_08 AC 119 ms
55,428 KB
testcase_09 AC 120 ms
55,412 KB
testcase_10 AC 120 ms
55,520 KB
testcase_11 WA -
testcase_12 AC 119 ms
55,248 KB
testcase_13 WA -
testcase_14 AC 120 ms
55,696 KB
testcase_15 AC 119 ms
55,592 KB
testcase_16 AC 120 ms
55,300 KB
testcase_17 AC 121 ms
55,404 KB
testcase_18 AC 120 ms
55,420 KB
testcase_19 AC 119 ms
55,868 KB
testcase_20 AC 121 ms
55,388 KB
testcase_21 AC 119 ms
55,852 KB
testcase_22 AC 159 ms
56,188 KB
testcase_23 AC 150 ms
56,488 KB
testcase_24 AC 154 ms
56,644 KB
testcase_25 AC 152 ms
55,812 KB
testcase_26 AC 134 ms
55,728 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==1){
            y=3;
        }else if(y==2){
            y=4;
        }
        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