結果
問題 | No.167 N^M mod 10 |
ユーザー |
|
提出日時 | 2016-11-20 23:19:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 467 bytes |
コンパイル時間 | 1,622 ms |
コンパイル使用メモリ | 166,672 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-22 01:37:16 |
合計ジャッジ時間 | 2,205 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;signed main(){string N, M; cin >> N >> M;if( M == "0" ) cout << 1 << endl, exit( 0 );int ld = N.back() - '0';int m = 1;for( int i = ld * ld % 10; i != ld; i = i * ld % 10 )++m;int x = 0;for( int i = 0; i < M.size(); ++i )x = x * 10 + M[ i ] - '0',x %= m;if( x == 0 ) x = m;int ans = 1;for( int i = 0; i < x; ++i )ans = ans * ld % 10;cout << ans << endl;return 0;}