結果
問題 | No.167 N^M mod 10 |
ユーザー |
![]() |
提出日時 | 2018-02-15 00:31:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 814 bytes |
コンパイル時間 | 690 ms |
コンパイル使用メモリ | 80,172 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-22 01:44:41 |
合計ジャッジ時間 | 1,911 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <iostream>#include <vector>#include <string>#include <cstring>#include <math.h>#include <cmath>#include <limits.h>#include <map>#include <set>#include <queue>#include <algorithm>#include <functional>#include <stdio.h>using namespace std;long long MOD = 1000000007;int main() {string N,M;cin >> N >> M;if ( M == "0" ) { cout << 1 << endl; return 0; }int a = N[N.length()-1] - '0';int b[4];int n = a;for ( int i = 0; i < 4; i++ ) {b[(i+1)%4] = n;n *= a;n %= 10;}string s;for ( int i = M.length()-1; i >= 0; i-- ) {s += M[i];if ( s.length() == 2 ) { break; }}if ( s.length() == 2 ) { swap( s[0], s[1] ); };int m = stoi(s);cout << b[m%4] << endl;return 0;}