結果
問題 | No.167 N^M mod 10 |
ユーザー |
![]() |
提出日時 | 2018-09-15 20:02:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 684 bytes |
コンパイル時間 | 1,540 ms |
コンパイル使用メモリ | 166,848 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-22 01:48:43 |
合計ジャッジ時間 | 2,458 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; #define INF 1000000000 using namespace std; #define MOD 1000000007 int main(void){ string n,m; cin>>n>>m; ll size_n=n.size(),size_m=m.size(); int ans; int q; if(m.size()<2)q=stoi(m); else q=stoi(m.substr(m.size()-2,2)); int p=n[n.size()-1]-'0'; //cout<<p<<" "<<q<<endl; int num[10][4]={{0,0,0,0},{1,1,1,1},{2,4,8,6},{3,9,7,1},{4,6,4,6},{5,5,5,5},{6,6,6,6},{7,9,3,1},{8,4,2,6},{9,1,9,1}}; int m4=q%4; if(m4!=0){ m4--; }else{ m4=3; } //cout<<p<<" "<<q<<" "<<m4<<endl; if(m=="0"){ ans=1; }else{ ans=num[p][m4]; } cout<<ans<<endl; }