結果

問題 No.167 N^M mod 10
ユーザー 37zigen37zigen
提出日時 2016-04-11 11:25:27
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 476 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 74,552 KB
実行使用メモリ 54,532 KB
最終ジャッジ日時 2024-04-14 23:57:34
合計ジャッジ時間 7,435 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
54,096 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 WA -
testcase_06 AC 132 ms
54,124 KB
testcase_07 AC 132 ms
53,700 KB
testcase_08 AC 136 ms
53,980 KB
testcase_09 AC 133 ms
54,140 KB
testcase_10 AC 132 ms
54,112 KB
testcase_11 AC 132 ms
53,992 KB
testcase_12 AC 130 ms
54,044 KB
testcase_13 AC 132 ms
54,288 KB
testcase_14 AC 131 ms
54,308 KB
testcase_15 AC 135 ms
54,048 KB
testcase_16 WA -
testcase_17 AC 133 ms
53,992 KB
testcase_18 WA -
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.util.*;
public class Main{
	public static void main(String[] args)throws Exception{
		new Main().sovle();
	}
	void sovle(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		//n^m mod 10
		System.out.println(pow(n,m,10));
		
	}
	int pow(int n,int m,int mod){
		int ans=1;
		int pow=n;
		while(m>=1){
			if(m%2==0){
				pow*=pow;
				pow%=mod;
				m/=2;
			}else{
				ans*=pow;
				ans%=mod;
				m--;
			}
		}
		return ans;
	}
	
}
0