結果
問題 | No.167 N^M mod 10 |
ユーザー |
![]() |
提出日時 | 2016-08-14 09:59:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 804 bytes |
コンパイル時間 | 1,073 ms |
コンパイル使用メモリ | 82,476 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-22 01:35:06 |
合計ジャッジ時間 | 2,115 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <algorithm> #include <iostream> #include <iomanip> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <vector> #include <cmath> using namespace std; #define FOR(i,s,e) for (int i = int(s); i != int(e); i++) #define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ISEQ(c) (c).begin(), (c).end() int main(){ string N; string M; cin >> N >> M; string N2 = N.substr(N.length()-1,1); int Nd = atoi(N2.c_str()); int Md; if (M.length() == 1){ Md = atoi(M.c_str()); if (Md == 0) { cout << 1 << endl; return 0; } }else{ string M2 = M.substr(M.length()-2,2); Md = atoi(M2.c_str()); } int ans = 1; if(Md == 0) Md += 4; FOR(i,0,Md){ ans = (ans * Nd)%10; } cout << ans << endl; return 0; }