結果
| 問題 |
No.167 N^M mod 10
|
| コンテスト | |
| ユーザー |
kohaku_kohaku
|
| 提出日時 | 2016-12-02 17:24:29 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 148 ms / 1,000 ms |
| コード長 | 746 bytes |
| コンパイル時間 | 2,337 ms |
| コンパイル使用メモリ | 75,240 KB |
| 実行使用メモリ | 41,292 KB |
| 最終ジャッジ日時 | 2024-09-22 01:38:10 |
| 合計ジャッジ時間 | 6,958 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String NSt = sc.next();
String MSt = sc.next();
int ans = pow(NSt,MSt);
System.out.println(ans);
}
static int pow(String A, String B){
if(B.equals("0")){
return 1;
}
int x = A.length();
int N = Integer.parseInt(A.substring(x-1));
int y = B.length();
if(y<3){y=3;}
int M = Integer.parseInt(B.substring(y-3));
int r = M%4;
int z = N;
if(r==0){
z = (int)(Math.pow(N,4))%10;
}else if(r!=1){
z = (int)(Math.pow(N,r))%10;
}
return z;
}
}
kohaku_kohaku