指数计算
7 月 1 日是建党日,从 1921 年到 2020 年,Communist Party of China已经带领中国人民走过了 99 年。
请计算:7 ^ 2020 mod 1921,其中 A mod B 表示 A 除以 B 的余数。
#include <iostream>
using namespace std;
//递归求解
int power(int b, int p, int s){
if(p != 0)
return (b*power(b,p-1,s)%s);
else
return 1;
}
int main(){
int b,p,s,res; //b为基数,P为指数,s为取余
cin >> b >> p >>s;
res = power(b,p,s);
cout << res;
return 0;
}