Skip to content

Instantly share code, notes, and snippets.

@luckypapa
Created September 6, 2015 23:50
Show Gist options
  • Save luckypapa/06ec9d847d7b89194d9a to your computer and use it in GitHub Desktop.
Save luckypapa/06ec9d847d7b89194d9a to your computer and use it in GitHub Desktop.
//https://www.acmicpc.net/problem/1009
#include <stdio.h>
int cache[8][4] = {
{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 lastComputer(int a, int b) {
int result;
a %= 10;
if (a == 1) {
return 1;
} else if (a == 0) {
return 10;
} else {
result = cache[a-2][(b-1)%4];
}
return result;
}
int main(void) {
int T = 0;
int a = 0, b = 0;
scanf("%d", &T);
while (T-- > 0) {
scanf("%d %d", &a, &b);
printf("%d\n", lastComputer(a, b));
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment