51nod 1004 【快速幂】

思路:
掐住最后一位,快速幂一发就好了

#include<cstdio>
#include <map>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

typedef __int64 LL;


int cal(int g,int x)
{
    int ans=1;
    while(g)
    {
        if(g%2)
            ans=(ans*x)%10;
        x=(x*x)%10;
        g>>=1;
    }
    return ans%10;
}

int main()
{
    int n;
    scanf("%d",&n);
    int ans;
    ans=cal(n,n%10);
    printf("%d",ans);
    return 0;
}

posted @ 2016-08-31 23:44  see_you_later  阅读(99)  评论(0编辑  收藏  举报