結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
4,376 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,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 1 ms
4,380 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;
/////////

int main(void){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(6);//
	
	string A,B;
	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';
		if(M == 0){
			P(1);
		}
		else{
			if(N==0 || N==1 || N==5){
				P(N);
			}
			else if(N%2==0){
				for(int i=0;i<4;++i){
					if(N==e[i]){
						P(e[(M+3+i)%4]);
						break;
					}	
				}
				
			}else{
				for(int i=0;i<4;++i){
					if(N==o[i]){
						P(o[(M+3+i)%4]);
						break;
					}
				}
			}
		}
	}else if(Bsize == 2){
		M = (B[Bsize-2]-'0')*10+B[Bsize-1]-'0';
////////
		if(N==0 || N==1 || N==5){
			P(N);
		}
		else if(N%2==0){
			for(int i=0;i<4;++i){
				if(N==e[i]){
					P(e[(M+3+i)%4]);
					break;
				}	
			}
			
		}else{
			for(int i=0;i<4;++i){
				if(N==o[i]){
					P(o[(M+3+i)%4]);
					break;
				}
			}
		}
/////////////
	}
	else{
		M = (B[Bsize-2]-'0')*10+B[Bsize-1]-'0';
		if(N==0 || N==1 || N==5){
			P(N);
		}
		else if(N%2==0){
			for(int i=0;i<4;++i){
				if(N==e[i]){
					P(e[(M+3+i)%4]);
					break;
				}	
			}
			
		}else{
			for(int i=0;i<4;++i){
				if(N==o[i]){
					P(o[(M+3+i)%4]);
					break;
				}
			}
		}
	}


	return 0;
}
0