ACM (TJU) : 1748


// http://acm.tju.edu.cn/toj/showp1748.html

#include <stdio.h>
#include <string.h>
#include <math.h>

int main ()
{
    char m [1010];
    char n [1010];

    while ( scanf ("%s %s", m, n) ) {

        if ( strcmp (m, "0") == 0 && strcmp (n, "0") == 0 )
            return 0;

        int last_m = m [strlen (m) - 1] - '0';

        int i = 0;
        int mod = 0;
        int length_n = strlen (n);

        while ( i < length_n )
            mod = (mod * 10 + (n [i++] - '0')) % 4;

        if ( mod == 0 && strcmp (n, "0") != 0)
            mod = 4;

        printf ("%0.lf\n", fmod (pow (last_m, mod), 10));
    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s