結果
| 問題 |
No.167 N^M mod 10
|
| ユーザー |
zaichu
|
| 提出日時 | 2017-11-23 21:36:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 679 bytes |
| コンパイル時間 | 1,703 ms |
| コンパイル使用メモリ | 168,052 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-27 05:58:27 |
| 合計ジャッジ時間 | 2,455 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 8 WA * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T x, T y)
{
if (y == 0)
return x;
return gcd(y, x % y);
}
template <typename T>
T lcm(T x, T y)
{
if (x == 0 || y == 0)
return 0;
return x / gcd(x, y) * y;
}
int main()
{
string N;
cin >> N;
string M;
cin >> M;
const int mod = 10;
int n = N[N.size() - 1] - '0';
int m = stoi(M.size() > 4 ? M.substr(M.size() - 4) : M);
if (m == 0)
{
cout << 1 << endl;
return 0;
}
m += 1;
m %= 4;
int ans = 1;
for (int i = 0; i < m; i++)
{
ans *= n;
ans %= mod;
}
cout << ans << endl;
}
zaichu