結果

問題 No.167 N^M mod 10
ユーザー kuramukuramu
提出日時 2016-01-29 11:35:10
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 732 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 74,816 KB
実行使用メモリ 53,728 KB
最終ジャッジ日時 2023-10-21 16:34:44
合計ジャッジ時間 5,070 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
53,388 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 54 ms
53,400 KB
testcase_06 AC 54 ms
53,400 KB
testcase_07 AC 54 ms
53,400 KB
testcase_08 AC 54 ms
53,392 KB
testcase_09 AC 54 ms
53,388 KB
testcase_10 AC 55 ms
53,404 KB
testcase_11 AC 54 ms
53,388 KB
testcase_12 AC 54 ms
53,388 KB
testcase_13 AC 55 ms
53,388 KB
testcase_14 AC 55 ms
53,412 KB
testcase_15 AC 54 ms
53,396 KB
testcase_16 AC 54 ms
53,396 KB
testcase_17 AC 55 ms
53,388 KB
testcase_18 AC 53 ms
53,396 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
	    	  int x = Integer.parseInt(stdReader.readLine());
	    	  int N = Integer.parseInt(stdReader.readLine());
	    	  int ans = pow(x, N,10) % 10;
	    	  System.out.println(ans);
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}
	public static int pow(int x,int n,int m){
		long temp = x;
		long ans = 1;
		while(n>0){
			if(n%2==0){
				temp = temp*temp % m;
				n /= 2;
			}else{
				n -= 1;
				ans = ans *temp % m;
			}
		}		
		return (int)ans;
	}
}
0