大意:输入整数n和k,输出n的k次幂的前三位和后三位
亮点:利用快速幂求后三位,利用k*log10(n)相关小数部分pow(10, 小数部分)求前三位
快速幂实现:pow4(int n, int k, int mod);
程序:
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define LL long long
#define ll __int64
#define mes(a, b) memset(a, b, sizeof(a))
using namespace std;
int n, k;
double fl;
int pow4(ll n, ll k, int mod)
{
ll ans = 1;
ll base = n;
while (k){
if (k & 1){
ans *= base;
ans %= mod;
}
base *= (base % mod); //debug data overflow
//ll
base %= mod;
k >>= 1; //debug >>
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
int tt; cin >> tt;
int ans1, ans2;
int kase = 0;
while (tt --){
cin >> n >> k;
ans2 = pow4(n, k, 1000);
fl = k*log10(n+0.0); //transform the type of data
fl -= int(fl); //debug ll()
ans1 = (int)pow(10.0, fl+2);
//association with digit number
printf("Case %d: %d %03d\n", ++kase, ans1, ans2);
//make up the blank place with 0
}
return 0;
}