#include #define DEBUGe #define NOP do{}while(0) #ifdef DEBUG #define TRACE(...) do{printf(__VA_ARGS__);fflush(stdout);}while(0) #define TRACECR do{printf("\n");fflush(stdout);}while(0) #else #define TRACE(...) NOP #define TRACECR NOP #endif //#define MOD (1000000007) #define MOD (10) int main( void ) { long aa; long bb; long cc; scanf("%ld", &aa ); scanf("%ld", &bb ); if( bb == 0 ) { printf("%d\n", 0); return 0; } else if( bb == 1 ) { printf("%d\n", aa % 10); return 0; } aa %= 10; bb %= 4; cc = aa; for(int i = 1; i < bb; i++) { cc = (cc * aa) %10; } cc %= 10; printf("%d\n", cc); return 0; }