結果

問題 No.167 N^M mod 10
ユーザー 37zigen37zigen
提出日時 2016-04-11 11:30:45
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 558 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 75,168 KB
実行使用メモリ 55,008 KB
最終ジャッジ日時 2024-04-14 23:57:42
合計ジャッジ時間 6,749 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 121 ms
54,248 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 125 ms
54,192 KB
testcase_07 AC 121 ms
53,868 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 120 ms
54,088 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 129 ms
54,080 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 160 ms
54,236 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 156 ms
54,432 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
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);
		String N=sc.next();
		String M=sc.next();
		int n=N.charAt(N.length()-1);
		int m=M.charAt(M.length()-1);
		//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