結果

問題 No.167 N^M mod 10
ユーザー kohaku_kohaku
提出日時 2016-11-20 03:09:15
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 786 bytes
コンパイル時間 4,255 ms
コンパイル使用メモリ 74,852 KB
実行使用メモリ 41,704 KB
最終ジャッジ日時 2024-11-27 06:37:08
合計ジャッジ時間 7,384 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22 WA * 5
権限があれば一括ダウンロードができます

ソースコード

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