快速幂

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;
int pow_(int a,int b,int c){
    int s=1;
    while(b!=0)
    {
        if(b&1) s=s*a%c;
        a=a*a%c;
        b>>=1;
    }
    return s;
}

int _tmain(int argc, _TCHAR* argv[])
{
    int a,b;
    cin>>a>>b;
    cout<<pow_(a,b,10);
    system("pause");
    return 0;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容