View Code of Problem 3696

#include<cstdio>
int qmi(int n,int m,int k)
{
    int res = 1 % k,t = n;
    while(m)
    {
        if(m & 1) res = res * t % k;
        t = t * t % k;
        m >>= 1;
    }
    return res;
}
int main()
{
    int n;
    while(scanf("%d",&n) != EOF)
    {
        printf("%d\n",qmi(n,n,10));
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 3696