結果
問題 |
No.167 N^M mod 10
|
ユーザー |
![]() |
提出日時 | 2016-01-29 11:35:10 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 732 bytes |
コンパイル時間 | 1,872 ms |
コンパイル使用メモリ | 74,480 KB |
実行使用メモリ | 37,436 KB |
最終ジャッジ日時 | 2024-09-21 17:51:01 |
合計ジャッジ時間 | 4,386 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 13 RE * 14 |
ソースコード
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; } }