結果
問題 | No.167 N^M mod 10 |
ユーザー | Grenache |
提出日時 | 2015-07-27 18:29:03 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,049 bytes |
コンパイル時間 | 5,510 ms |
コンパイル使用メモリ | 75,044 KB |
実行使用メモリ | 51,052 KB |
最終ジャッジ日時 | 2023-09-23 04:02:33 |
合計ジャッジ時間 | 6,643 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,600 KB |
testcase_01 | AC | 44 ms
49,288 KB |
testcase_02 | AC | 48 ms
49,288 KB |
testcase_03 | AC | 48 ms
49,588 KB |
testcase_04 | AC | 47 ms
49,188 KB |
testcase_05 | AC | 44 ms
49,240 KB |
testcase_06 | AC | 44 ms
49,228 KB |
testcase_07 | AC | 44 ms
49,356 KB |
testcase_08 | AC | 44 ms
49,248 KB |
testcase_09 | AC | 43 ms
49,404 KB |
testcase_10 | AC | 43 ms
49,236 KB |
testcase_11 | AC | 43 ms
49,584 KB |
testcase_12 | AC | 43 ms
49,272 KB |
testcase_13 | AC | 43 ms
49,328 KB |
testcase_14 | AC | 43 ms
49,700 KB |
testcase_15 | AC | 44 ms
49,396 KB |
testcase_16 | AC | 44 ms
49,228 KB |
testcase_17 | AC | 44 ms
49,224 KB |
testcase_18 | AC | 43 ms
49,240 KB |
testcase_19 | AC | 45 ms
49,160 KB |
testcase_20 | AC | 45 ms
49,292 KB |
testcase_21 | AC | 44 ms
47,132 KB |
testcase_22 | AC | 48 ms
49,176 KB |
testcase_23 | AC | 48 ms
49,052 KB |
testcase_24 | AC | 47 ms
49,160 KB |
testcase_25 | AC | 48 ms
51,052 KB |
testcase_26 | WA | - |
testcase_27 | AC | 47 ms
49,116 KB |
testcase_28 | AC | 46 ms
49,120 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Iterator; public class Main_yukicoder167 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int MOD = 10; String n = sc.next(); String m = sc.next(); int nn = mod(n, MOD); if (nn == 0) { if (m.equals("0")) { System.out.println("1"); } else { System.out.println("0"); } } else { int loop = mod(m, 4) - 1; if (loop < 0) { loop = 3; } int ret = nn; for (int i = 0; i < loop; i++) { ret *= nn; } System.out.println(ret % MOD); } sc.close(); } private static int mod(String x, int MOD) { char[] xx = x.toCharArray(); long ret = 0; for (int i = 0; i < xx.length; i++) { ret *= 10; ret += xx[i] - '0'; ret %= MOD; } return (int)ret; } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } }