#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e7; //自定义取模的数据,视数据大小的情况而定
//a ^ b
ll ksm(ll a, ll b, ll mod) { //time_complex=O(logn)
ll ans = 1, base = a;
while (b != 0) {
if ((b & 1) != 0) { //“b & 1”指取b的二进制数的最末位
ans = (ans * base) % mod; //累乘,以便随时对ans做出贡献。
}
base = (base * base) % mod;
b >>= 1; //右移1位,删去最低位。
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); //断开同步流
ll a, b, result;
clock_t my_start, my_end;
cin >> a >> b;
my_start = clock();
//该函数返回值是硬件滴答数
result = ksm(a, b, mod);
cout << a << "^" << b << "=" << result << endl;
my_end = clock();
cout << "time=" << ((double)my_end - my_start) / CLK_TCK << "s" << endl;
//要换算成秒,需要除以CLK_TCK或者 CLK_TCKCLOCKS_PER_SEC
return 0;
}
仅供参考!!!!