結果

問題 No.167 N^M mod 10
ユーザー やまぞう
提出日時 2015-04-04 00:07:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 619 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 55,128 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-22 01:13:12
合計ジャッジ時間 1,437 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;

string N;
string M;

void input(istream& in)
{
	in >> N >> M;
}

int resolve(const char *n, const char *m)
{
	int nn = atoi(n + strlen(n) - 1);
	if (m[0] == '0' && m[1] == 0) return 1;
	if (m[1] != 0) m += strlen(m) - 2;
	int mm = atoi(m);
	mm = ((mm + 3) % 4) + 1;
	switch (mm) {
	case 1: return nn % 10;
	case 2: return (nn * nn) % 10;
	case 3: return (nn * nn * nn) % 10;
	default: return (nn * nn * nn * nn) % 10;
	}
}

int main(int argc, char **argv)
{
	input(cin);
	cout << resolve(N.c_str(), M.c_str()) << endl;
}
0