結果

問題 No.167 N^M mod 10
ユーザー 37zigen
提出日時 2016-04-11 11:25:27
言語 Java
(openjdk 23)
結果
RE  
実行時間 -
コード長 476 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 74,224 KB
実行使用メモリ 54,368 KB
最終ジャッジ日時 2024-10-04 06:01:00
合計ジャッジ時間 7,675 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 WA * 3 RE * 14
権限があれば一括ダウンロードができます

ソースコード

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