結果

問題 No.167 N^M mod 10
ユーザー IL_mstaIL_msta
提出日時 2015-06-15 18:45:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,121 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 77,380 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-21 02:14:33
合計ジャッジ時間 1,850 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
4,380 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <cmath>

#include <string>
#include <list>
#include <queue>
#include <vector>
#include <complex>

/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) std::cout<<(p)<<std::endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
string A,B;
int main(void){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(6);//
	
	
	cin>>A>>B;
	int N,M;
	N = A[A.size()-1]-'0';
	int Bsize = B.size();
	int e[4] = {2,4,8,6};
	int o[4] = {3,9,7,1};
	if(Bsize == 1){
		M = B[0]-'0';
	}else{
		M = (B[Bsize-2]-'0')*10+B[Bsize-1]-'0';
	}

	if(Bsize == 1 && M == 0){//n^0
		P(1);
	}
	else if(N==0 || N==1 || N==5 || N==6){
		P(N);
	}
	else
	{
		if(N%2==0){
			for(int i=0;i<4;++i){
				if(N==e[i]){
					P(e[ (M*(i+1)+3+i) % 4 ]);
					break;
				}	
			}
			
		}else{
			for(int i=0;i<4;++i){
				if(N==o[i]){
					P(o[ (M*(i+1)+3+i) % 4 ]);
					break;
				}
			}
		}
	}

	return 0;
}
0