結果
| 問題 |
No.167 N^M mod 10
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-07 18:27:03 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,848 bytes |
| コンパイル時間 | 186 ms |
| コンパイル使用メモリ | 29,824 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-12 14:15:49 |
| 合計ジャッジ時間 | 1,182 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 WA * 2 |
ソースコード
#include <stdio.h>
#include <string.h>
int main(void)
{
char N[10002], M[10002];
int N_length, M_length, tmp;
scanf("%s%s", N, M);
N_length = strlen(N);
M_length = strlen(M);
if (N[N_length - 1] == '0') puts("0");
else if (M[0] == '0') puts("1");
else {
if (N[N_length - 1] == '1' || N[N_length - 1] == '5' || N[N_length - 1] == '6') printf("%c", N[N_length - 1]);
else if (N[N_length - 1] == '4' || N[N_length - 1] == '9') {
if ((M[M_length - 1] - '0') % 2) printf("%c", N[N_length - 1]);
else {
if (N[N_length - 1] == '4') puts("6");
else puts("1");
}
}
else {
tmp = 10 * (M[M_length - 2] - '0') + M[M_length - 1] - '0';
if (N[N_length - 1] == '2') {
if (tmp % 4 == 1) printf("%c", N[N_length - 1]);
else if (tmp % 4 == 2) puts("4");
else if (tmp % 4 == 3) puts("8");
else puts("6");
}
else if (N[N_length - 1] == '3') {
if (tmp % 4 == 1) printf("%c", N[N_length - 1]);
else if (tmp % 4 == 2) puts("9");
else if (tmp % 4 == 3) puts("7");
else puts("1");
}
else if (N[N_length - 1] == '7') {
if (tmp % 4 == 1) printf("%c", N[N_length - 1]);
else if (tmp % 4 == 2) puts("9");
else if (tmp % 4 == 3) puts("3");
else puts("1");
}
else {
if (tmp % 4 == 1) printf("%c", N[N_length - 1]);
else if (tmp % 4 == 2) puts("4");
else if (tmp % 4 == 3) puts("2");
else puts("6");
}
}
}
return 0;
}