結果
問題 |
No.167 N^M mod 10
|
ユーザー |
|
提出日時 | 2016-12-20 16:52:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 1,239 bytes |
コンパイル時間 | 1,420 ms |
コンパイル使用メモリ | 167,880 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-22 01:38:21 |
合計ジャッジ時間 | 2,240 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include "bits/stdc++.h" #define REP(i,a,b) for(int i=a;i<b;++i) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define all(a) begin(a),end(a) #define ifnot(a) if(not (a)) #define dump(x) cerr << #x << " = " << (x) << endl using namespace std; // #define int ll #ifdef _MSC_VER const bool test = true; #else const bool test = false; #endif int dx[] = { 0,1,0,-1 }; int dy[] = { 1,0,-1,0 }; #define LINF ((ll)1 << 60) #define INF (1 << 28) // ull mod = (int)1e9 + 7; //..................... const int MAX = (int)2e5 + 5; ull mod = 10; /* pow(x,n)はx^nを返すよ! */ template<class T, class U> T mod_pow(T x, U n) { T res = 1; while (n > 0) { if (n & 1) res = res * x; x = x * x; x %= mod; n >>= 1; res %= mod; } return res; } void solve() { string n, m; cin >> n >> m; int n_int = n.back() - '0'; int m_int; if (m == "0") m_int = 0; else if (m.size() == 1){ m_int = stoi(m); } else { m_int = stoi(m.substr(m.size() - 2, 2)); if (m_int == 0) m_int = 4; } cout << mod_pow(n_int, m_int) << endl; } signed main() { cout << fixed << setprecision(20); rep(i, 1) solve(); return 0; }