結果

問題 No.167 N^M mod 10
コンテスト
ユーザー kuramu
提出日時 2016-01-29 11:35:10
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
RE  
実行時間 -
コード長 732 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,438 ms
コンパイル使用メモリ 81,080 KB
実行使用メモリ 39,680 KB
最終ジャッジ日時 2026-04-09 23:18:33
合計ジャッジ時間 3,631 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 RE * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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