結果
問題 | No.167 N^M mod 10 |
ユーザー |
![]() |
提出日時 | 2017-11-23 21:49:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 585 bytes |
コンパイル時間 | 1,654 ms |
コンパイル使用メモリ | 167,164 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-22 01:43:07 |
合計ジャッジ時間 | 2,203 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#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() { const int mod = 10; string N; cin >> N; string M; cin >> M; if (M == "0") cout << 1 << endl; else { int m = stoi(M.size() > 3 ? M.substr(M.size() - 3) : M); int n = N.back() - '0'; cout << (int)pow(n, (m + 3) % 4 + 1) % mod << endl; } }