結果
問題 | No.167 N^M mod 10 |
ユーザー |
|
提出日時 | 2017-12-01 03:42:14 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 525 bytes |
コンパイル時間 | 1,652 ms |
コンパイル使用メモリ | 160,116 KB |
実行使用メモリ | 54,016 KB |
最終ジャッジ日時 | 2024-11-06 19:20:20 |
合計ジャッジ時間 | 2,683 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 WA * 1 |
ソースコード
#include <bits/stdc++.h>using namespace std;int a[10] = {1, 1, 4, 4, 2, 1, 1, 4, 4, 2};string n, m;int modString(string s, int mod) {int n = s.size();if (n == 0) return 0;return (modString(s.substr(0, n - 1), mod) * 10 % mod + (s[n - 1] - '0')) % mod;}int main(void) {cin >> n >> m;int b = a[n[n.size() - 1]] - '0';int rem = modString(m, b), ans = 1;if (!rem) rem = b;for (int i = 0; i < rem; i++) {ans *= n[n.size() - 1] - '0';ans %= 10;}cout << ans << endl;return 0;}