結果
| 問題 |
No.167 N^M mod 10
|
| コンテスト | |
| ユーザー |
ty70
|
| 提出日時 | 2016-10-27 16:03:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 689 bytes |
| コンパイル時間 | 1,810 ms |
| コンパイル使用メモリ | 158,564 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-24 04:55:17 |
| 合計ジャッジ時間 | 2,343 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 WA * 5 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int period[10] = { 1, 1, 4, 4, 2, 1, 1, 4, 4, 2 };
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
string N, M; cin >> N >> M;
int res = 0;
if (M.length() == 1 && M[0] == '0'){
res = 1;
}else{
int m = (int)(M[M.length() - 1] - '0');
if (M.length() >= 2)
m = (int)(M[M.length() - 2] - '0') * 10 + m;
int n = (int)(N[N.length() - 1] - '0');
res = n;
for (int i = 1; i < m % period[n]; ++i){
res = (res * n) % 10;
} // end for
} // end if
cout << res << endl;
return 0;
}
ty70