結果
| 問題 |
No.167 N^M mod 10
|
| ユーザー |
kpinkcat
|
| 提出日時 | 2023-11-04 10:47:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 846 bytes |
| コンパイル時間 | 1,151 ms |
| コンパイル使用メモリ | 108,072 KB |
| 最終ジャッジ日時 | 2025-02-17 19:08:50 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 TLE * 1 -- * 15 |
ソースコード
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;
int div(string s, int div){
int i;
i = stoi(s.substr(0, 1));
s = s.substr(1);
while (s.size()){
i *= 10;
i += stoi(s.substr(0, 1));
s = s.substr(1);
i %= div;
}
return i;
}
int main(){
string n, m;
cin >> n >> m;
int t1 = n[n.size()-1] - '0';
ll r, ans = t1;
vector<ll> modulo{1, 1, 4, 4, 2, 1, 1, 4, 4, 2};
if (modulo[t1] == 1) {
cout << n[n.size()-1] << endl;
return 0;
} else {
r = div(m, modulo[t1]);
while(--r){
ans *= t1;
ans %= 10;
}
cout << ans << endl;
}
}
kpinkcat