結果
問題 | No.167 N^M mod 10 |
ユーザー |
|
提出日時 | 2015-12-03 16:47:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 1,029 bytes |
コンパイル時間 | 548 ms |
コンパイル使用メモリ | 58,520 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-22 01:23:57 |
合計ジャッジ時間 | 1,458 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <iostream> #include <cstring> #include <algorithm> #include <limits.h> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; /* ここからが本編 */ /* */ /* mod_pow(x,n)はx^nを返すよ! */ /* modを定義してから使ってね! */ #define mod 10 ll mod_pow(ll x,ll n) { ll res = 1; while(n > 0) { if(n&1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int n; void suuzi(char s[],int i,int& j) { for(; j < n/2; j++) { if(s[i+j] < '0' || '9' < s[i+j]) break; } } int main(void) { int i,j,k,l; static char s[10005]; int n,m; cin >> s; n = s[strlen(s)-1] - '0'; cin >> s; for(i=0;s[i];i++) { if(s[i] != '0') break; } if(strlen(s) == 1) m = s[strlen(s)-1] - '0'; else m = atoi(s+strlen(s)-2); if(m == 0 && i != strlen(s)) m = 4; if(m == 0) cout << "1\n" ; else cout << mod_pow(n%10,m%4+4)%10 << endl; return 0; }