結果

問題 No.167 N^M mod 10
ユーザー naimonon77
提出日時 2016-12-20 16:47:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,211 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 169,420 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-14 11:24:46
合計ジャッジ時間 3,054 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#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));
	}
	cout << mod_pow(n_int, m_int) << endl;;
}

signed main() {
	cout << fixed << setprecision(20);
	rep(i, 1) solve();
	return 0;
}
0