結果
| 問題 |
No.167 N^M mod 10
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-04-12 22:47:02 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,327 bytes |
| コンパイル時間 | 196 ms |
| コンパイル使用メモリ | 30,336 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-22 01:52:42 |
| 合計ジャッジ時間 | 961 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
ソースコード
// yukicoder: No.169 何分かかるの
// 2019.4.12 bal4u
#include <stdio.h>
#if 0
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int ins(char *s) // 文字列の入力 スペース以下の文字で入力終了
{
char *p = s;
do *s = gc();
while (*s++ > ' ');
*--s = 0;
return s - p;
}
#define N 1000000000
int num[1200]; int w;
void mpStr2Num(int *num, int w, char *str)
{
char *ss;
int *nn;
int k, x;
ss = str + w;
x = 0, k = 1, nn = num;
do {
x += (*--ss - '0') * k;
k *= 10;
if (k == N || ss == str) *++nn = x, x = 0, k = 1;
} while (ss != str);
*num = nn - num;
}
// 多倍長整数 za を 整数 ab で割ったあまり = za % zb
int mpMod(int *za, int zb)
{
int i = *za;
int *aa = za + *za;
int ca = 0;
long long x;
while (i--) {
x = (long long)N * ca + *aa--;
ca = (int)(x % zb);
}
return ca;
}
int tbl[10][4] = { {0,0,0,0},{1,1,1,1},{6,2,4,8},{1,3,9,7},{6,4,6,4},
{5,5,5,5},{6,6,6,6},{1,7,9,3},{6,8,4,2},{1,9,1,9} };
char n[10005];
int main()
{
int base, r;
w = ins(n);
base = n[w - 1] & 0xf;
w = ins(n);
if (n[0] == '0') { puts("1"); return 0; }
if (base == 0) { puts("0"); return 0; }
mpStr2Num(num, w, n);
r = mpMod(num, 4);
printf("%d\n", tbl[base][r]);
return 0;
}
bal4u