light OJ 1282 - Leading and Trailing 数学 || double技巧

时间:2023-03-10 04:45:17
light OJ 1282 - Leading and Trailing  数学 || double技巧

http://lightoj.com/volume_showproblem.php?problem=1282

light OJ 1282 - Leading and Trailing  数学 || double技巧

light OJ 1282 - Leading and Trailing  数学 || double技巧

light OJ 1282 - Leading and Trailing  数学 || double技巧

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset> //int calc(LL a, LL b, int k) { //a^b的前k + 1位
// double res = b * log10(a * 1.0) - (LL)(b * log10(a * 1.0)); //小数部分
// return (int)pow(10.0, k + res);
//}
int calc(double a, LL b, int k) {
double ans = , base = a;
while (b) {
if (b & ) {
ans = ans * base;
}
b >>= ;
base = base * base;
while (ans >= ) ans /= ; //保留前3位
while (base >= ) base /= ;
}
return (int)ans;
}
int quick_pow(LL a, LL b, int MOD) {
LL ans = , base = a % MOD;
while (b) {
if (b & ) ans = ans * base % MOD;
b >>= ;
base = base * base % MOD;
}
return ans;
}
void work() {
LL a, b;
cin >> a >> b;
static int f = ;
printf("Case %d: %d %03d\n", ++f, calc(a, b, ), quick_pow(a, b, ));
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}